Getting `initialize': wrong number of arguments(1 for 0) (ArgumentError) for simple ruby app
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?
ruby arguments
add a comment |Â
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?
ruby arguments
add a comment |Â
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?
ruby arguments
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?
ruby arguments
ruby arguments
edited Sep 8 '13 at 2:20
asked Sep 8 '13 at 2:18
nilesvm
1341211
1341211
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
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
.
add a comment |Â
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.
3
You saved my day @7stud!
â FloatingRock
Sep 28 '14 at 11:08
Dropping by, years later, to say thank you.
â amaleemur
Apr 21 '16 at 0:51
dropping by, years later after I first upvoted this answer, to say thank you again.
â lakesare
Feb 26 '17 at 12:32
add a comment |Â
For require_relative 'user'
move old 'user.rb' up one level rename 'user2.rb' to 'user.rb'. Also, there is a typo.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
.
add a comment |Â
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
.
add a comment |Â
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
.
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
.
answered Sep 8 '13 at 2:23
sawa
129k27197299
129k27197299
add a comment |Â
add a comment |Â
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.
3
You saved my day @7stud!
â FloatingRock
Sep 28 '14 at 11:08
Dropping by, years later, to say thank you.
â amaleemur
Apr 21 '16 at 0:51
dropping by, years later after I first upvoted this answer, to say thank you again.
â lakesare
Feb 26 '17 at 12:32
add a comment |Â
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.
3
You saved my day @7stud!
â FloatingRock
Sep 28 '14 at 11:08
Dropping by, years later, to say thank you.
â amaleemur
Apr 21 '16 at 0:51
dropping by, years later after I first upvoted this answer, to say thank you again.
â lakesare
Feb 26 '17 at 12:32
add a comment |Â
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.
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.
answered Sep 8 '13 at 7:11
7stud
28.9k96081
28.9k96081
3
You saved my day @7stud!
â FloatingRock
Sep 28 '14 at 11:08
Dropping by, years later, to say thank you.
â amaleemur
Apr 21 '16 at 0:51
dropping by, years later after I first upvoted this answer, to say thank you again.
â lakesare
Feb 26 '17 at 12:32
add a comment |Â
3
You saved my day @7stud!
â FloatingRock
Sep 28 '14 at 11:08
Dropping by, years later, to say thank you.
â amaleemur
Apr 21 '16 at 0:51
dropping by, years later after I first upvoted this answer, to say thank you again.
â lakesare
Feb 26 '17 at 12:32
3
3
You saved my day @7stud!
â FloatingRock
Sep 28 '14 at 11:08
You saved my day @7stud!
â FloatingRock
Sep 28 '14 at 11:08
Dropping by, years later, to say thank you.
â amaleemur
Apr 21 '16 at 0:51
Dropping by, years later, to say thank you.
â amaleemur
Apr 21 '16 at 0:51
dropping by, years later after I first upvoted this answer, to say thank you again.
â lakesare
Feb 26 '17 at 12:32
dropping by, years later after I first upvoted this answer, to say thank you again.
â lakesare
Feb 26 '17 at 12:32
add a comment |Â
For require_relative 'user'
move old 'user.rb' up one level rename 'user2.rb' to 'user.rb'. Also, there is a typo.
add a comment |Â
For require_relative 'user'
move old 'user.rb' up one level rename 'user2.rb' to 'user.rb'. Also, there is a typo.
add a comment |Â
For require_relative 'user'
move old 'user.rb' up one level rename 'user2.rb' to 'user.rb'. Also, there is a typo.
For require_relative 'user'
move old 'user.rb' up one level rename 'user2.rb' to 'user.rb'. Also, there is a typo.
answered Nov 10 at 21:17
samanthi22
12
12
add a comment |Â
add a comment |Â
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid â¦
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid â¦
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18679769%2fgetting-initialize-wrong-number-of-arguments1-for-0-argumenterror-for-sim%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown