Another option that hasn't been mentioned yet is to use delegation.
You can have a wrapper around a hash that contains all your additional
methods and references a Hash instance.
Hi Robert,
Could you elaborate with code pls?
Kind regards
Nev
Another option that hasn't been mentioned yet is to use delegation.
You can have a wrapper around a hash that contains all your additional
methods and references a Hash instance.
Hi Robert,
Could you elaborate with code pls?
Kind regards
Nev
class MyHash
def initialize
@hash = {}
end
# Do something special to the hash
def square_all
@hash.each{ |k,v| @hash[k] = v*v }
end
# Pass any method I don't understand on to the hash
def method_missing(meth, *args, &block)
@hash.send(meth, *args, &block)
end
end
On May 18, 2005, at 7:01 PM, Neville Burnell wrote:
Another option that hasn't been mentioned yet is to use delegation.
You can have a wrapper around a hash that contains all your additional
methods and references a Hash instance.Could you elaborate with code pls?