Created
June 10, 2013 22:08
-
-
Save joegiralt/5752841 to your computer and use it in GitHub Desktop.
method chaining
This file contains hidden or 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
# Chain at least 5 method calls to an object. Reduce this operation one chain at a time. | |
# Don't just use the methods below, make up your own chain and try to see if you can do something fun with Ruby like in the example. | |
# Example: | |
# puts "start".reverse.slice(0,2).concat("uth").capitalize | |
# # => Truth | |
# Because: | |
# puts "start".reverse | |
# #=> trats | |
# puts "start".reverse.slice(0,2) | |
# #=> tr | |
# puts "start".reverse.slice(0,2).concat("uth") | |
# #=> truth | |
# puts "start".reverse.slice(0,2).concat("uth").capitalize | |
# #=> Truth | |
# At any given point in the chain, there is an evaluation that then receives the next method call. | |
puts "racecar".upcase | |
puts "racecar".upcase.slice(0..3) | |
puts "racecar".upcase.slice(0..3).reverse | |
puts "racecar".upcase.slice(0..3).reverse.concat(" RAC") | |
puts "racecar".upcase.slice(0..3).reverse.concat(" RAC").reverse | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment