Created
December 14, 2015 21:58
-
-
Save TSMMark/fa19386117951526af6d to your computer and use it in GitHub Desktop.
Ruby Object send
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 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