| Class | Range |
| In: |
lib/pp.rb
lib/yaml/rubytypes.rb |
Returns true if obj is an element of rng, false otherwise. Conveniently, === is the comparison operator used by case statements.
case 79 when 1..50 then print "low\n" when 51..75 then print "medium\n" when 76..100 then print "high\n" end
produces:
high
Returns true if obj is between beg and end, i.e beg <= obj <= end (or end exclusive when exclude_end? is true).
("a".."z").cover?("c") #=> true
("a".."z").cover?("5") #=> false
Returns the object that defines the end of rng.
(1..10).end #=> 10 (1...10).end #=> 10
Returns true if obj is an element of rng, false otherwise. If beg and end are numeric, comparison is done according magnitude of values.
("a".."z").include?("g") # => true
("a".."z").include?("A") # => false
Returns true if obj is an element of rng, false otherwise. If beg and end are numeric, comparison is done according magnitude of values.
("a".."z").include?("g") # => true
("a".."z").include?("A") # => false
Iterates over rng, passing each nth element to the block. If the range contains numbers, n is added for each iteration. Otherwise step invokes succ to iterate through range elements. The following code uses class Xs, which is defined in the class-level documentation.
range = Xs.new(1)..Xs.new(10)
range.step(2) {|x| puts x}
range.step(3) {|x| puts x}
produces:
1 x
3 xxx
5 xxxxx
7 xxxxxxx
9 xxxxxxxxx
1 x
4 xxxx
7 xxxxxxx
10 xxxxxxxxxx
ruby-doc.org is hosted and run by James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, Arizona. Ruby-doc.org was created in 2002 to promote the Ruby language and to help other Ruby hackers.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.