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/.
I think there is a typo: "def initalize"
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
···
On Fri, 4 Jan 2008 00:39:26 +0900, ole __ wrote
What am I doing wrong?
--
Posted via http://www.ruby-forum.com/\.
NilObject does not have a method called new.
···
--
Posted via http://www.ruby-forum.com/.
Ahh right. I needed somebody else's eyes to see that.
Thanks
···
--
Posted via http://www.ruby-forum.com/.
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
···
On Jan 3, 2008 11:16 AM, Hugh Themm <mchughson@gmail.com> wrote:
NilObject does not have a method called new.
--
Rick DeNatale
My blog on Ruby
http://talklikeaduck.denhaven2.com/
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
Introduce Null Object
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/\.
That is the solution
Run
# ruby script/generate scaffold Product Admin:string
instead of
# ruby script/generate scaffold Product Admin
Blessings
juldtb@gmail.com
···
--
Posted via http://www.ruby-forum.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
juldtb@gmail.com
I think you must have replied to the wrong thread or something.
···
--
Posted via http://www.ruby-forum.com/\.