Created
January 26, 2012 04:33
-
-
Save nagachika/1681013 to your computer and use it in GitHub Desktop.
godscope
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
# `publish' all private instance methods | |
ObjectSpace.each_object(Module) do |mod| | |
mod.private_instance_methods(false).each do |meth| | |
mod.__send__(:public, meth) | |
end | |
end | |
# define accessor methods as ghost method | |
class Object | |
def method_missing(meth, *args) | |
if /^(.+)=$/ =~ meth.to_s and args.size == 1 | |
name = $1.to_sym | |
elsif args.empty? | |
name = meth | |
else | |
return super | |
end | |
if self.instance_variable_defined?("@#{name}") | |
if meth == name | |
self.instance_variable_get("@#{name}") | |
else | |
self.instance_variable_set("@#{name}", args[0]) | |
end | |
else | |
super | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment