Class: ActiveRecord::Refined::AST::Case::When

Inherits:
Node
  • Object
show all
Defined in:
lib/active_record/refined/ast.rb

Overview

What a when is until its then arrives. A Node so that using it as one says what is missing rather than reaching Active Record as something it cannot read.

Instance Method Summary collapse

Methods inherited from Node

#as, #asc, #collate, #desc

Constructor Details

#initialize(kase, condition) ⇒ When

Returns a new instance of When.



925
926
927
928
# File 'lib/active_record/refined/ast.rb', line 925

def initialize(kase, condition)
  @kase = kase
  @condition = condition
end

Instance Method Details

#then(value = nil, &block) ⇒ AST::Case

THEN value, as a value or a block, for the when before it.

Returns:



932
933
934
935
936
# File 'lib/active_record/refined/ast.rb', line 932

def then(value = nil, &block)
  Case.new(@kase.operand,
           @kase.whens + [[@condition, Case.argument(:then, value, block)]],
           @kase.default)
end