Created
January 16, 2013 02:13
-
-
Save jredville/4544034 to your computer and use it in GitHub Desktop.
Back of the envelope method mirror in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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