Sha256: d1b429375762bd34f62cdfda82a60f57e47b4d34bb0bbd1ebc4523bdd418848a

Contents?: true

Size: 586 Bytes

Versions: 21

Compression:

Stored size: 586 Bytes

Contents

class Code
  class Node
    class Ternary < Node
      def initialize(parsed)
        @left = Node::Statement.new(parsed.delete(:left))
        @middle = Node::Statement.new(parsed.delete(:middle))
        if parsed.key?(:right)
          @right = Node::Statement.new(parsed.delete(:right))
        end
        super(parsed)
      end

      def evaluate(**args)
        if @left.evaluate(**args).truthy?
          @middle.evaluate(**args)
        elsif @right
          @right.evaluate(**args)
        else
          ::Code::Object::Nothing.new
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
template-ruby-0.5.6 lib/code/node/ternary.rb
language-ruby-0.5.6 lib/code/node/ternary.rb
code-ruby-0.5.6 lib/code/node/ternary.rb
template-ruby-0.5.5 lib/code/node/ternary.rb
language-ruby-0.5.5 lib/code/node/ternary.rb
code-ruby-0.5.5 lib/code/node/ternary.rb
template-ruby-0.5.4 lib/code/node/ternary.rb
language-ruby-0.5.4 lib/code/node/ternary.rb
code-ruby-0.5.4 lib/code/node/ternary.rb
template-ruby-0.5.3 lib/code/node/ternary.rb
language-ruby-0.5.3 lib/code/node/ternary.rb
code-ruby-0.5.3 lib/code/node/ternary.rb
template-ruby-0.5.2 lib/code/node/ternary.rb
language-ruby-0.5.2 lib/code/node/ternary.rb
code-ruby-0.5.2 lib/code/node/ternary.rb
language-ruby-0.5.1 lib/code/node/ternary.rb
template-ruby-0.5.1 lib/code/node/ternary.rb
code-ruby-0.5.1 lib/code/node/ternary.rb
template-ruby-0.5.0 lib/code/node/ternary.rb
language-ruby-0.5.0 lib/code/node/ternary.rb