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

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:innew’
from permutations.rb:9

What am I doing wrong?

I think there is a typo: “def initalize”

On Fri, 4 Jan 2008 00:39:26 +0900, ole __ wrote

Will yield:

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

Ahh right. I needed somebody else’s eyes to see that.
Thanks

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

Will yield:

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

What am I doing wrong?
You’ve typoed initalize

Fred

NilObject does not have a method called new.

Hi,

You mistyped initialize.

Tiago M.

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.

That is the solution
Run

ruby script/generate scaffold Product Admin:string

instead of

ruby script/generate scaffold Product Admin

Blessings
[email protected]

On Jan 3, 2008 11:16 AM, Hugh T. [email protected] 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/

Julix Andres wrote:

That is the solution
Run

ruby script/generate scaffold Product Admin:string

instead of

ruby script/generate scaffold Product Admin

Blessings
[email protected]

I think you must have replied to the wrong thread or something.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs