Skip to content

Instantly share code, notes, and snippets.

@jredville
Created January 16, 2013 02:13
Show Gist options
  • Save jredville/4544034 to your computer and use it in GitHub Desktop.
Save jredville/4544034 to your computer and use it in GitHub Desktop.
Back of the envelope method mirror in Ruby
class Mirror < BasicObject
def initialize(target)
@target = target
end
def method_missing(sym, *args)
@target.method(sym) rescue nil
end
def respond_to_missing?(sym, priv=false)
!!send(sym)
end
end
if __FILE__ == $0
m = Mirror.new(Object.new)
m.to_s # Object's to_s method
m.to_s.call # "#<Object:0x....>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment