Skip to content

Instantly share code, notes, and snippets.

@TSMMark
Created December 14, 2015 21:58
Show Gist options
  • Save TSMMark/fa19386117951526af6d to your computer and use it in GitHub Desktop.
Save TSMMark/fa19386117951526af6d to your computer and use it in GitHub Desktop.
Ruby Object send
class Person
def call_mom!
puts "I just called mom."
end
def wash_car!
puts "I just washed my car."
end
def walk_the_cat!
puts "I just walked the cat."
end
end
things_to_do = ["call_mom!", "wash_car!", "walk_the_cat!"]
me = Person.new
done_things = things_to_do.each { |name_of_a_thing| me.send(name_of_a_thing) }
# The above calls these methods in order:
# me.call_mom!
# me.wash_car!
# me.walk_the_cat!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment