Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/rangeary.rb
Overview
Overwrites its equal operator
Direct Known Subclasses
Instance Method Summary collapse
-
#==(other) ⇒ Object
Updated Array#==.
- #equals_before_rangeary ⇒ Object
Instance Method Details
#==(other) ⇒ Object
Updated Array#==
This modifies the original equality operator so that it returns true when both self and other are practically empty, that is, if #empty_element? and/or empty? are true for both, they are equal.
This modification is necessary because Rangeary#empty? never returns true; when it has no Range elements, it holds RangeExtd::NONE or equivalent, in whih case Rangeary#empty_element? returns true.
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 |
# File 'lib/rangeary.rb', line 1408 def ==(other) return true if equals_before_rangeary other # It was false. Is it? # eg., (Rangeary[RangeExtd::NONE] == []) is true, # because Rangeary[] with zero components does not exist! # Now either other or self is guranteed to be Rangeary. self_empt = (respond_to?(:empty_element?) ? empty_element? : empty?) other_empt = (other.respond_to?(:empty_element?) ? other.empty_element? : other.empty?) self_empt && other_empt end |
#equals_before_rangeary ⇒ Object
1395 |
# File 'lib/rangeary.rb', line 1395 alias_method :equals_before_rangeary, :== |