Created
September 13, 2015 11:12
-
-
Save tsevdos/fa82d7afa1960a0b2f6c to your computer and use it in GitHub Desktop.
Ruby tips : Ranges
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
(1..10) === 4 # => true | |
(1...10) === 10 # => false |
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
(1..10).to_a # => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
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
(1..10).each_entry {|val| puts "#{val}"} | |
(1..10).each_with_index {|val, i| puts "#{i} : #{val}"} |
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
1..10 # => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 | |
1...10 # => 1, 2, 3, 4, 5, 6, 7, 8, 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment