Getting `initialize': wrong number of arguments(1 for 0) (ArgumentError) for simple ruby app











up vote
8
down vote

favorite
1












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?










share|improve this question




























    up vote
    8
    down vote

    favorite
    1












    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?










    share|improve this question


























      up vote
      8
      down vote

      favorite
      1









      up vote
      8
      down vote

      favorite
      1






      1





      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 8 '13 at 2:20

























      asked Sep 8 '13 at 2:18









      nilesvm

      1341211




      1341211
























          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.






          share|improve this answer




























            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.






            share|improve this answer

















            • 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


















            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.






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              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

























              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.






              share|improve this answer

























                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.






                share|improve this answer























                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 8 '13 at 2:23









                  sawa

                  128k27192296




                  128k27192296
























                      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.






                      share|improve this answer

















                      • 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















                      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.






                      share|improve this answer

















                      • 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













                      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.






                      share|improve this answer












                      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.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      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














                      • 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










                      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.






                      share|improve this answer

























                        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.






                        share|improve this answer























                          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.






                          share|improve this answer












                          For require_relative 'user' move old 'user.rb' up one level rename 'user2.rb' to 'user.rb'. Also, there is a typo.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 10 at 21:17









                          samanthi22

                          11




                          11






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Florida Star v. B. J. F.

                              Error while running script in elastic search , gateway timeout

                              Adding quotations to stringified JSON object values