mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
6d225a9870
Some of the nodes classes are missing either one or many of the common comparison methods #hash, #eql? and #==. This makes comparision and working with the ast sometimes painful, as equality or operations likes array differences (which uses a hash behind the scene) produces unexpected results. A test has been added that ensures that every descendants of Node: * have all 3 methods * that all 3 methods were defined from the same class * that the class defining all 3 is also a descendant of Node, to avoid the default ones that rely on identity only
27 lines
436 B
Ruby
27 lines
436 B
Ruby
# frozen_string_literal: true
|
|
module Arel
|
|
module Nodes
|
|
class BindParam < Node
|
|
attr_accessor :value
|
|
|
|
def initialize(value)
|
|
@value = value
|
|
super()
|
|
end
|
|
|
|
def hash
|
|
[self.class, self.value].hash
|
|
end
|
|
|
|
def eql?(other)
|
|
other.is_a?(BindParam) &&
|
|
value == other.value
|
|
end
|
|
alias :== :eql?
|
|
|
|
def nil?
|
|
value.nil?
|
|
end
|
|
end
|
|
end
|
|
end
|