Last active
December 17, 2015 07:29
-
-
Save cciollaro/5573112 to your computer and use it in GitHub Desktop.
Method definition for a wildcard method. You never know what you're gonna get. Example usage:
27.random_method
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
class Object | |
def random_method | |
begin | |
method = self.methods.sample.to_s | |
print "Calling #{method}: " | |
return_val = self.instance_eval(method) | |
puts return_val | |
rescue Exception => e | |
puts "it failed (#{e.message})" | |
retry | |
end | |
return return_val | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment