Created
October 21, 2011 22:44
-
-
Save samstokes/1305183 to your computer and use it in GitHub Desktop.
Stick this in your .irbrc and smoke it
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
def methods_returning(answer, *args) | |
# probably want to filter out some methods | |
# e.g. ones that mutate their receiver... | |
blacklist = %w() | |
(methods - blacklist).select do |method| | |
guinea_pig = begin | |
clone | |
rescue TypeError => e | |
raise unless e.message =~ /can't clone/ | |
self | |
end | |
begin | |
guinea_pig.send(method, *args) == answer | |
rescue ArgumentError, LocalJumpError | |
rescue TypeError, NoMethodError, NameError, IndexError, SystemCallError, NotImplementedError => e | |
args_inspected = args.inspect | |
args_nice = args_inspected[1, args_inspected.length - 2] | |
puts "#{self.inspect}.#{method}(#{args_nice}) throws #{e.class}: #{e}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment