Initialize Ruby codes error -
i tried run these codes:
class dog def set_name(name) @dogname = name end def get_name return @dogname end def talk return "awww" end def initialize(title, description) @title = title @description = description end end doggy = dog.new doggy.set_name('sam') puts doggy.get_name puts doggy.talk bogart = dog.new('the book', 'the road not taken') puts bogart.to_s puts bogart.inspect
i did make sure every argument correct. however, got following errors.
c:\ruby200\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=argv.shift) c:/users/todd/rubymineprojects/untitled1/test.rb c:/users/todd/rubymineprojects/untitled1/test.rb:15:in `initialize': wrong number of arguments (0 2) (argumenterror) c:/users/todd/rubymineprojects/untitled1/test.rb:22:in `new' c:/users/todd/rubymineprojects/untitled1/test.rb:22:in `<top (required)>' -e:1:in `load' -e:1:in `<main>' process finished exit code 1
tried best can't find issue. idea miss?
class dog def set_name(name) @dogname = name end def get_name return @dogname end def talk return "awww" end def initialize(title, description) @title = title @description = description end end #that cause error because new method have 2 arguments. doggy = dog.new bogart = dog.new('the book', 'the road not taken') bogart.set_name('sam') puts bogart.get_name puts bogart.talk puts bogart.to_s puts bogart.inspect
Comments
Post a Comment