extending Forwardable delegates to hash : Forwardable « Collections « Ruby






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

1.extend Forwardable
2.Easing the Delegation Blues