Methods
Public Instance methods
A thing really should know itself. This simply returns self.
[ show source ]
# File lib/facets/core/range/to_r.rb, line 5 def to_r self end
A thing really should know itself. This simply returns self.
Note: This does not internally effect the Ruby interpretor such that it can coerce Range-like objects into a Range.
[ show source ]
# File lib/facets/core/range/to_range.rb, line 9 def to_range self end
Returns a two element array of the relationship between two Ranges.
Diagram:
Relationship Returns self |-----------| r |-----------| [0,0] self |-----------| r |---------| [-1,-1] self |---------| r |-----------| [1,1] self |-----------| r |----------| [-1,0] self |-----------| r |-----------| [-1,1] etc.
Example:
(0..3).umbrella(1..2) #=> [-1,-1]
[ show source ]
# File lib/facets/core/range/umbrella.rb, line 31 def umbrella(r) s = self.first <=> r.first e = r.last <=> self.last return s,e end
Uses the Range#umbrella method to determine if another Range is anywhere within this Range.
(1..3).within?(0..4) #=> true
[ show source ]
# File lib/facets/core/range/within.rb, line 10 def within?(rng) case rng.umbrella(self) when [0,0], [-1,0], [0,-1], [-1,-1] return true else return false end end