diff options
Diffstat (limited to 'activerecord/lib/arel/nodes/case.rb')
-rw-r--r-- | activerecord/lib/arel/nodes/case.rb | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/activerecord/lib/arel/nodes/case.rb b/activerecord/lib/arel/nodes/case.rb index 50ea1e0be2..22c2da98dd 100644 --- a/activerecord/lib/arel/nodes/case.rb +++ b/activerecord/lib/arel/nodes/case.rb @@ -1,31 +1,32 @@ # frozen_string_literal: true + module Arel module Nodes class Case < Arel::Nodes::Node attr_accessor :case, :conditions, :default - def initialize expression = nil, default = nil + def initialize(expression = nil, default = nil) @case = expression @conditions = [] @default = default end - def when condition, expression = nil + def when(condition, expression = nil) @conditions << When.new(Nodes.build_quoted(condition), expression) self end - def then expression + def then(expression) @conditions.last.right = Nodes.build_quoted(expression) self end - def else expression + def else(expression) @default = Else.new Nodes.build_quoted(expression) self end - def initialize_copy other + def initialize_copy(other) super @case = @case.clone if @case @conditions = @conditions.map { |x| x.clone } @@ -36,7 +37,7 @@ module Arel [@case, @conditions, @default].hash end - def eql? other + def eql?(other) self.class == other.class && self.case == other.case && self.conditions == other.conditions && |