Skip to content

Instantly share code, notes, and snippets.

Created November 3, 2013 15:38
Show Gist options
  • Save anonymous/7291532 to your computer and use it in GitHub Desktop.
Save anonymous/7291532 to your computer and use it in GitHub Desktop.
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