S
Stephan Mueller
Hi,
if I have an array-like class, is it possible to call the index with a
block?
class MyClass
def find(key)
return nil
end
def [](key)
if (val = find(key))
return val
else
return yield(key) if block_given?
end
end
end
c = MyClass.new
c[:test] { "default" }
triggers a syntax error (Ruby 1.8.6).
Is there a way to accomplish this or do i need to do tricks like giving
the block to the constructor?
Cheers,
Steph.
if I have an array-like class, is it possible to call the index with a
block?
class MyClass
def find(key)
return nil
end
def [](key)
if (val = find(key))
return val
else
return yield(key) if block_given?
end
end
end
c = MyClass.new
c[:test] { "default" }
triggers a syntax error (Ruby 1.8.6).
Is there a way to accomplish this or do i need to do tricks like giving
the block to the constructor?
Cheers,
Steph.