Skip to content

Instantly share code, notes, and snippets.

@lukewendling
Created July 11, 2014 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukewendling/0f58454085bb99b6df5f to your computer and use it in GitHub Desktop.
Save lukewendling/0f58454085bb99b6df5f to your computer and use it in GitHub Desktop.
Ruby Range examples
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