Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
delegatable.rb
module Delegatable
def self.included(base)
base.class_eval do
def self.delegate_method(method, to)
define_method(method) do |*args|
instance_variable_get(to).__send__(method, *args)
end
end
end
end
end
class X
include Delegatable
delegate_method :push, :@que
attr_accessor :que
def initialize
@que = []
end
end
x = X.new
x.push 1, 2, 3
p x.que
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.