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

O

ole __

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?
 
S

steffen_kory

I think there is a typo: "def initalize"


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

Frederick Cheung

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
 
R

Rick DeNatale

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
 
O

ole __

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

Julix Andres

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

instead of
# ruby script/generate scaffold Product Admin


Blessings
(e-mail address removed)
 
O

Oliver Saunders

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

instead of
# ruby script/generate scaffold Product Admin


Blessings
(e-mail address removed)

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top