Class : Range Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

..

A

prints entire range

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A

prints entire range up to the last number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

.cover?

A

cover?(val) → true or false click to toggle source
Returns true if obj is between beg and end, i.e beg <= obj <= end (or end exclusive when exclude_end? is true).
ex.
(“a”..”z”).cover?(“c”) –> true
(“a”..”z”).cover?(“5”) –> false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

.each do | n |

A
each {| i | block } → rng click to toggle source
each → an_enumerator
Iterates over the elements rng, passing each in turn to the block. You can only iterate if the start object of the range supports the succ method (which means that you can’t iterate over ranges of Float objects).
ex.
(10..15).each do |n|
   print n, ' '
end
produces: 10 11 12 13 14 15
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

.end

A

returns the object which defines the end
ex.
(1..10).end #=> 10
(1…10).end #=> 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

.eql?(object)

A

eql?(obj) → true or false click to toggle source
Returns true only if obj is a Range, has equivalent beginning and end items (by comparing them with eql?), and has the same exclude_end?
ex.
(0..2).eql?(0..2) —>true
(0..2).eql?(0…2) —>false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly