Skip to content

Instantly share code, notes, and snippets.

@bbl
Last active November 14, 2017 15:16
Show Gist options
  • Save bbl/1589fa83348789080aea9f1ed54fd5e3 to your computer and use it in GitHub Desktop.
Save bbl/1589fa83348789080aea9f1ed54fd5e3 to your computer and use it in GitHub Desktop.
Ruby delegation

Use the delegate instance methods flexibly in class:

require 'forwardable'

class MyHash

  extend(Forwardable)

  include(Enumerable)



  def_delegators(:@hash, :[], :[]=, :delete, :each,

                         :keys, :values, :length,

                         :empty?, :has_key?)

end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment