forwardable.rb 403 B

12345678910111213
  1. # My own version of the forwardable mixin in with the def_delegator
  2. # However it must be used with extend, not include
  3. module Forwardable
  4. # Forwards methods to the given named instance
  5. def def_delegator(obj_name, name, alias_name = nil)
  6. alias_name ||= name
  7. define_method(alias_name) do |*args|
  8. obj = self.instance_variable_get(obj_name)
  9. obj.send(name, *args)
  10. end
  11. end
  12. end