Skip to content

Instantly share code, notes, and snippets.

@samstokes
Created October 21, 2011 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samstokes/1305183 to your computer and use it in GitHub Desktop.
Save samstokes/1305183 to your computer and use it in GitHub Desktop.
Stick this in your .irbrc and smoke it
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