"wrong number of arguments" What? I must be thick or somethi

Discussion in 'Ruby' started by ole __, Jan 3, 2008.

  1. ole __

    ole __ Guest

    class PermutationIterator
    def initalize(data_set, nested = nil)
    @data_set = data_set
    @nested = nested || NilObject.new
    @key = 0
    @fresh = true
    end
    end
    a = PermutationIterator.new [1, 2, 3]

    Will yield:

    permutations.rb:9:in `initialize': wrong number of arguments (1 for 0)
    (ArgumentError)
    from permutations.rb:9:in `new'
    from permutations.rb:9

    What am I doing wrong?
    --
    Posted via http://www.ruby-forum.com/.
     
    ole __, Jan 3, 2008
    #1
    1. Advertising

  2. ole __

    Guest

    I think there is a typo: "def initalize"


    On Fri, 4 Jan 2008 00:39:26 +0900, ole __ wrote
    > class PermutationIterator
    > def initalize(data_set, nested = nil)
    > @data_set = data_set
    > @nested = nested || NilObject.new
    > @key = 0
    > @fresh = true
    > end
    > end
    > a = PermutationIterator.new [1, 2, 3]
    >
    > Will yield:
    >
    > permutations.rb:9:in `initialize': wrong number of arguments (1 for 0)
    > (ArgumentError) from permutations.rb:9:in `new' from

    permutations.rb:9
    >
    > What am I doing wrong?
    > --
    > Posted via http://www.ruby-forum.com/.
     
    , Jan 3, 2008
    #2
    1. Advertising

  3. On 3 Jan 2008, at 15:39, ole __ wrote:

    > class PermutationIterator
    > def initalize(data_set, nested = nil)
    > @data_set = data_set
    > @nested = nested || NilObject.new
    > @key = 0
    > @fresh = true
    > end
    > end
    > a = PermutationIterator.new [1, 2, 3]
    >
    > Will yield:
    >
    > permutations.rb:9:in `initialize': wrong number of arguments (1 for 0)
    > (ArgumentError)
    > from permutations.rb:9:in `new'
    > from permutations.rb:9
    >
    > What am I doing wrong?

    You've typoed initalize

    Fred
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    >
     
    Frederick Cheung, Jan 3, 2008
    #3
  4. ole __

    Tiago Macedo Guest

    Hi,

    You mistyped initialize.

    Tiago Macedo

    ole __ wrote:
    > class PermutationIterator
    > def initalize(data_set, nested = nil)
    > @data_set = data_set
    > @nested = nested || NilObject.new
    > @key = 0
    > @fresh = true
    > end
    > end
    > a = PermutationIterator.new [1, 2, 3]
    >
    > Will yield:
    >
    > permutations.rb:9:in `initialize': wrong number of arguments (1 for 0)
    > (ArgumentError)
    > from permutations.rb:9:in `new'
    > from permutations.rb:9
    >
    > What am I doing wrong?
     
    Tiago Macedo, Jan 3, 2008
    #4
  5. ole __

    ole __ Guest

    Re: "wrong number of arguments" What? I must be thick or som

    Ahh right. I needed somebody else's eyes to see that.
    Thanks
    --
    Posted via http://www.ruby-forum.com/.
     
    ole __, Jan 3, 2008
    #5
  6. ole __

    Hugh Themm Guest

    Hugh Themm, Jan 3, 2008
    #6
  7. On Jan 3, 2008 11:16 AM, Hugh Themm <> wrote:
    > NilObject does not have a method called new.


    Yes, but he hadn't gotten to that point yet.

    @nested = nested || NilObject.new

    won't work, and is probably unnecessary.

    @nested = nested

    is probably enough, unless you really want to be able to pass false to
    indicate no nested, which would be a strange interface for a ruby
    method I think. But it that's what's actually desired, it should be

    @nested = nested || nil



    --
    Rick DeNatale

    My blog on Ruby
    http://talklikeaduck.denhaven2.com/
     
    Rick DeNatale, Jan 3, 2008
    #7
  8. ole __

    ole __ Guest

    > Yes, but he hadn't gotten to that point yet.

    Right. And I only posted a cut down version of the code. NilObject is
    defined in the full version.

    > @nested = nested || NilObject.new
    >
    > won't work, and is probably unnecessary.


    Interesting. Let me make certain you understand my intentions first.
    NilObject looks like this:

    class NilObject
    def method_missing(name, *params); end
    end

    It just swallows messages. It is an implementation of the Introduce Null
    Object refactor
    http://www.refactoring.com/catalog/introduceNullObject.html This means
    that I don't have to continuously repeat checks for nil. It's explained
    a bit better here
    http://www.industriallogic.com/xp/refactoring/nullObject.html

    This is a concept that has come straight out of Java so I'm interested
    if there is a more ruby way of doing such things.
    --
    Posted via http://www.ruby-forum.com/.
     
    ole __, Jan 4, 2008
    #8
  9. ole __

    Julix Andres Guest

    That is the solution
    Run
    # ruby script/generate scaffold Product Admin:string

    instead of
    # ruby script/generate scaffold Product Admin


    Blessings

    --
    Posted via http://www.ruby-forum.com/.
     
    Julix Andres, Aug 13, 2008
    #9
  10. Julix Andres wrote:
    > That is the solution
    > Run
    > # ruby script/generate scaffold Product Admin:string
    >
    > instead of
    > # ruby script/generate scaffold Product Admin
    >
    >
    > Blessings
    >


    I think you must have replied to the wrong thread or something.
    --
    Posted via http://www.ruby-forum.com/.
     
    Oliver Saunders, Aug 14, 2008
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Russ
    Replies:
    1
    Views:
    567
    =?Utf-8?B?Q2hhcmxlcyBDaGVu?=
    Nov 29, 2004
  2. Adam Lipscombe
    Replies:
    5
    Views:
    732
    Richard Corfield
    Apr 24, 2004
  3. Benoit
    Replies:
    0
    Views:
    452
    Benoit
    Aug 11, 2004
  4. Mango
    Replies:
    0
    Views:
    517
    Mango
    Jan 9, 2005
  5. Igor Soares
    Replies:
    4
    Views:
    210
    Igor Soares
    Apr 28, 2011
Loading...

Share This Page