1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/arel/nodes/bind_param.rb
Maxime Lapointe 6d225a9870 Add missing hash, eql?, == to various node classes
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
2017-07-25 09:50:27 -04:00

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