Skip to content

Instantly share code, notes, and snippets.

@takuma-saito
Created May 12, 2020 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuma-saito/30ce47b5d99fa6f13982d228572b2da2 to your computer and use it in GitHub Desktop.
Save takuma-saito/30ce47b5d99fa6f13982d228572b2da2 to your computer and use it in GitHub Desktop.
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