1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] Add equality and hashing to selectors.

This commit is contained in:
Nathan Weizenbaum 2010-02-25 17:08:48 -08:00
parent 1a22566387
commit 305a88f9f9

View file

@ -22,6 +22,29 @@ module Sass
def inspect
to_a.map {|e| e.is_a?(Sass::Script::Node) ? "\#{#{e.to_sass}}" : e}.join
end
# Returns a hash code for this selector object.
#
# By default, this is based on the value of \{#to\_a},
# so if that contains information irrelevant to the identity of the selector,
# this should be overridden.
#
# @return [Fixnum]
def hash
to_a.hash
end
# Checks equality between this and another object.
#
# By default, this is based on the value of \{#to\_a},
# so if that contains information irrelevant to the identity of the selector,
# 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.to_a.eql?(to_a)
end
end
# A comma-separated sequence of selectors.
@ -69,6 +92,21 @@ module Sass
def inspect
members.map {|m| m.inspect}.join(", ")
end
# Returns a hash code for this sequence.
#
# @return [Fixnum]
def hash
members.hash
end
# Checks equality between this and another object.
#
# @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.members.eql?(self.members)
end
end
# An operator-separated sequence of
@ -130,6 +168,22 @@ module Sass
def inspect
members.map {|m| m.inspect}.join(" ")
end
# Returns a hash code for this sequence.
#
# @return [Fixnum]
def hash
members.reject {|m| m == "\n"}.hash
end
# Checks equality between this and another object.
#
# @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.members.reject {|m| m == "\n"}.eql?(self.members.reject {|m| m == "\n"})
end
end
# A unseparated sequence of selectors
@ -180,6 +234,21 @@ module Sass
def inspect
members.map {|m| m.inspect}.join
end
# Returns a hash code for this sequence.
#
# @return [Fixnum]
def hash
members.hash
end
# Checks equality between this and another object.
#
# @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.members.eql?(self.members)
end
end
# A parent-referencing selector (`&` in Sass).