Getting `initialize': wrong number of arguments(1 for 0) (ArgumentError) for simple ruby app
up vote
8
down vote
favorite
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 |
up vote
8
down vote
favorite
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 |
up vote
8
down vote
favorite
up vote
8
down vote
favorite
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
up vote
7
down vote
accepted
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 |
up vote
52
down vote
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 |
up vote
0
down vote
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
up vote
7
down vote
accepted
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 |
up vote
7
down vote
accepted
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 |
up vote
7
down vote
accepted
up vote
7
down vote
accepted
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
128k27192296
128k27192296
add a comment |
add a comment |
up vote
52
down vote
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 |
up vote
52
down vote
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 |
up vote
52
down vote
up vote
52
down vote
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.2k96081
28.2k96081
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 |
up vote
0
down vote
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 |
up vote
0
down vote
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 |
up vote
0
down vote
up vote
0
down vote
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
11
11
add a comment |
add a comment |
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