lib/antelope/generation/recognizer/rule.rb in antelope-0.1.11 vs lib/antelope/generation/recognizer/rule.rb in antelope-0.2.0
- old
+ new
@@ -17,11 +17,11 @@
attr_reader :left
# The right-hand side of the rule.
#
# @return [Array<Ace::Token>]
- attr_accessor :right
+ attr_reader :right
# The current position inside of the rule.
#
# @return [Numeric]
attr_reader :position
@@ -158,10 +158,16 @@
else
super
end
end
+ def ==(other)
+ hash == other.hash if other.respond_to?(:hash)
+ end
+
+ alias_method :eql?, :==
+
# Fuzzily compares this object to another object. If the
# other object is not a rule, it delegates the comparison.
# Otherwise, it fuzzily compares the left and right sides.
#
# @param other [Object] the object to compare.
@@ -190,22 +196,20 @@
# @note This is not intended for use. It is only defined to be
# compatible with Hashs (and by extension, Sets).
# @private
# @return [Object]
def hash
- to_a.hash
+ @_hash ||= to_a.hash
end
- alias_method :eql?, :==
-
# Creates an array representation of this class.
#
# @note This is not intended for use. It is only defined to
# make equality checking easier, and to create a hash.
# @private
# @return [Array<(Ace::Token::Nonterminal, Array<Ace::Token>, Numeric)>]
def to_a
- [left, right, position]
+ @_array ||= [left, right, position]
end
end
end
end
end