Created
July 11, 2014 15:49
-
-
Save lukewendling/0f58454085bb99b6df5f to your computer and use it in GitHub Desktop.
Ruby Range examples
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
1.9.3-p545 :001 > (1..2) | |
=> 1..2 | |
1.9.3-p545 :002 > (1..2).class | |
=> Range | |
1.9.3-p545 :003 > (1..2).include?(1) | |
=> true | |
1.9.3-p545 :004 > (1..2).include?(3) | |
=> false | |
1.9.3-p545 :005 > 1..2.include?(3) | |
NoMethodError: undefined method `include?' for 2:Fixnum | |
from (irb):5 | |
from /home/luke/.rvm/rubies/ruby-1.9.3-p545/bin/irb:12:in `<main>' | |
1.9.3-p545 :006 > 1 === 1..2 | |
ArgumentError: bad value for range | |
from (irb):6 | |
from /home/luke/.rvm/rubies/ruby-1.9.3-p545/bin/irb:12:in `<main>' | |
1.9.3-p545 :007 > 1 === (1..2) | |
=> false | |
1.9.3-p545 :008 > 1 === (0..2) | |
=> false | |
1.9.3-p545 :009 > (1..2) === 1 | |
=> true | |
1.9.3-p545 :010 > (1..2) === 3 | |
=> false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment