Created
July 10, 2013 15:09
-
-
Save AndrewRadev/5967093 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def god_mode | |
Object.class_eval do | |
def method_missing(m, *args, &block) | |
if private_methods.include?(m) | |
send(m, *args, &block) | |
else | |
super | |
end | |
end | |
end | |
end | |
def mortal_mode | |
Object.class_eval do | |
def method_missing(*) | |
super | |
end | |
end | |
end | |
class Foo | |
def bar | |
"baz" | |
end | |
private | |
def baz | |
"SECRET" | |
end | |
end | |
Foo.new.bar # => "baz" | |
Foo.new.baz rescue "ERROR" # => "ERROR" | |
god_mode | |
Foo.new.bar # => "baz" | |
Foo.new.baz # => "SECRET" | |
mortal_mode | |
Foo.new.bar # => "baz" | |
Foo.new.baz rescue "ERROR" # => "ERROR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment