Created
February 5, 2015 17:18
-
-
Save georgi/2c5c11998a3acd2a632d to your computer and use it in GitHub Desktop.
Enumerators and Enumerables
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
# Iterator methods without blocks are called Enumerators | |
[1,2,3].each_index # => #<Enumerator: [1, 2, 3]:each_index> | |
0.upto(10) # => #<Enumerator: 0:upto(10)> | |
# You can call any Enumerable method on Enumerators | |
[1,2,3].each_index.map {|i| i + 10 } # => [10, 11, 12] | |
0.upto(10).map {|i| i + 10 } # => [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] | |
# See documentation about Enumerables | |
# http://ruby-doc.org/core-2.1.5/Enumerable.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment