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










8














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




























    8














    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


























      8












      8








      8


      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


















          7














          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




























            53














            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


















            0














            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',
              autoActivateHeartbeat: false,
              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









              7














              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

























                7














                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























                  7












                  7








                  7






                  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

                  129k27197299




                  129k27197299























                      53














                      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















                      53














                      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













                      53












                      53








                      53






                      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.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












                      • 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











                      0














                      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

























                        0














                        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























                          0












                          0








                          0






                          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

                          12




                          12



























                              draft saved

                              draft discarded
















































                              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.




                              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

                              Top Tejano songwriter Luis Silva dead of heart attack at 64

                              ReactJS Fetched API data displays live - need Data displayed static

                              政党