This is my first ruby app. And I am a stack overflow virgin... When I run the following program:
class NameApp
def intialize(name)
@names = []
end
def name_question
print "What is your name? "
answer = gets.chomp
@names += answer.to_s
puts "The number of characters in your name is " + names.length
end
def name_length
if @names.length > 25 then
print "Your name is longer than 25 characters."
else
print "Your name is too short."
end
end
end
name_app = NameApp.new("Test1")
name_app.class # => NameApp
name_app.name_question
name_app.name_length
I get this simple error message result:
name.rb:26:in `initialize': wrong number of arguments(1 for 0) (ArgumentError)
from nameapp.rb:26:in `new'
from nameapp.rb:26:in `<main>'
Can you help me trouble shoot?
You spelled "initialize" wrong. I did that a few times too when I was starting out, and that was hard to debug. Why ruby didn't name it "init", I'll never know.
Since you have not defined the method initialize
for NameApp
, by default, it takes zero arguments, but you passed one argument "Test1"
via the constructor new
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With