Created
January 31, 2011 03:45
-
-
Save nicwn/803606 to your computer and use it in GitHub Desktop.
This begs for a little more explanation...
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
def test_methods_can_be_invoked_by_sending_the_message | |
mc = MessageCatcher.new | |
assert mc.send(:caught?) #Note: so this is the same as mc.caught? | |
end | |
def test_methods_can_be_invoked_more_dynamically #Note: or it shoudl say, calling a method is the same as sending a message to the class object. | |
mc = MessageCatcher.new | |
assert mc.send("caught?") | |
assert mc.send("caught" + ? ) # What do you need to add to the first string? | |
assert mc.send("CAUGHT?".____ ) # What would you need to do to the string? | |
end | |
def test_send_with_underscores_will_also_send_messages | |
mc = MessageCatcher.new | |
assert_equal __, mc.__send__(:caught?) | |
# THINK ABOUT IT: | |
# | |
# Why does Ruby provide both send and __send__ ? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment