Created
November 3, 2013 15:38
-
-
Save anonymous/7291532 to your computer and use it in GitHub Desktop.
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
class SomeClass | |
def a_field(arg) | |
puts "I'm a_field: #{arg}" | |
end | |
def b_field(arg) | |
puts "I'm b_field: #{arg}" | |
end | |
def some_other_method | |
end | |
end | |
list_of_methods = SomeClass.instance_methods.select {|method| method.to_s.include? "_field"} | |
=> [:a_field, :b_field] | |
list_of_methods.each do |method| | |
SomeClass.new.method(:"#{method}").call("test") | |
end | |
=> "I'm a_field: test" | |
=> "I'm b_field: test" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment