Skip to content

Instantly share code, notes, and snippets.

@burningTyger
Last active October 29, 2015 21:04
Show Gist options
  • Select an option

  • Save burningTyger/d292381727116631d4c7 to your computer and use it in GitHub Desktop.

Select an option

Save burningTyger/d292381727116631d4c7 to your computer and use it in GitHub Desktop.
require "delegate"
module X
def initialize(*)
super
__getobj__.class.instance_methods(false).each do |meth|
define_singleton_method(meth) { __getobj__.send(meth) || "Is nil"}
end
end
end
class A < SimpleDelegator
include X
end
class B
def hi
"hi"
end
def ho
end
end
b=B.new
a=A.new(b)
puts a.hi
puts a.ho
class C
def hi
end
def ho
"ho"
end
end
c=C.new
a=A.new(c)
puts a.hi
puts a.ho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment