Created
June 11, 2015 16:53
-
-
Save at1as/dc3a29d3b68f45d42857 to your computer and use it in GitHub Desktop.
Find Necessary Ruby Method for Desired Output
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
#!/usr/bin/env ruby | |
## Find necessary method for desired result | |
## entering: | |
## jason$ method_find.rb "HELLO" "hello" | |
## returns: | |
## HELLO.downcase == hello | |
## HELLO.swapcase == hello | |
def method?(current, desired, debug: false) | |
valid_methods = [] | |
current.methods.each do |method| | |
begin | |
if current.send(method) == desired.to_s | |
puts "METHOD #{method} produces desired result" if debug | |
valid_methods << method.to_s | |
else | |
puts "METHOD #{method} DOES NOT produce desired result" if debug | |
end | |
rescue => e | |
puts "METHOD #{method} caused an exception : #{e}" if debug | |
end | |
end | |
valid_methods | |
end | |
methods = method?(ARGV[0], ARGV[1], debug: false) | |
puts ?\n | |
methods.each do |method| | |
puts "#{ARGV[0]}.#{method} == #{ARGV[1]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment