extending Forwardable delegates to hash
require 'forwardable'
class RandomAccessHash
extend Forwardable
def initialize
@delegate_to = {}
end
def_delegators :@delegate_to, :[], "[]="
end
ra = RandomAccessHash.new
ra["A"] = 4.60
ra["B"] = 1.94
ra["C"] = 2.01
puts ra["D"]
Related examples in the same category