lib/sass/selector/simple.rb in sass-3.3.0.rc.6 vs lib/sass/selector/simple.rb in sass-3.3.0
- old
+ new
@@ -44,11 +44,11 @@
# so if that contains information irrelevant to the identity of the selector,
# this should be overridden.
#
# @return [Fixnum]
def hash
- @_hash ||= to_a.hash
+ @_hash ||= equality_key.hash
end
# Checks equality between this and another object.
#
# By default, this is based on the value of \{#to\_a},
@@ -56,11 +56,11 @@
# this should be overridden.
#
# @param other [Object] The object to test equality against
# @return [Boolean] Whether or not this is equal to `other`
def eql?(other)
- other.class == self.class && other.hash == hash && other.to_a.eql?(to_a)
+ other.class == self.class && other.hash == hash && other.equality_key.eql?(equality_key)
end
alias_method :==, :eql?
# Unifies this selector with a {SimpleSequence}'s {SimpleSequence#members members array},
# returning another `SimpleSequence` members array
@@ -91,9 +91,19 @@
return sels + [self] unless i
sels[0...i] + [self] + sels[i..-1]
end
protected
+
+ # Returns the key used for testing whether selectors are equal.
+ #
+ # This is based on \{#to\_a}, with adjacent strings merged so that
+ # selectors constructed in different ways are considered equivalent.
+ #
+ # @return [Array<String, Sass::Script::Tree::Node>]
+ def equality_key
+ @equality_key ||= Sass::Util.merge_adjacent_strings(to_a)
+ end
# Unifies two namespaces,
# returning a namespace that works for both of them if possible.
#
# @param ns1 [String, nil] The first namespace.