Sha256: e353b22804823b710d072e61ffaf790d656ec89d96caffdeacc36ef9c589345b

Contents?: true

Size: 615 Bytes

Versions: 32

Compression:

Stored size: 615 Bytes

Contents

# frozen_string_literal: true

class Code
  class Node
    class Ternary < Node
      def initialize(parsed)
        @left = Node::Statement.new(parsed.delete(:left))
        @middle = Node::Statement.new(parsed.delete(:middle))
        @right = Node::Statement.new(parsed.delete(:right)) if parsed.key?(
          :right
        )
        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

32 entries across 32 versions & 1 rubygems

Version Path
code-ruby-0.10.4 lib/code/node/ternary.rb
code-ruby-0.10.3 lib/code/node/ternary.rb
code-ruby-0.10.2 lib/code/node/ternary.rb
code-ruby-0.10.1 lib/code/node/ternary.rb
code-ruby-0.10.0 lib/code/node/ternary.rb
code-ruby-0.9.3 lib/code/node/ternary.rb
code-ruby-0.9.2 lib/code/node/ternary.rb
code-ruby-0.9.1 lib/code/node/ternary.rb
code-ruby-0.9.0 lib/code/node/ternary.rb
code-ruby-0.8.5 lib/code/node/ternary.rb
code-ruby-0.8.4 lib/code/node/ternary.rb
code-ruby-0.8.3 lib/code/node/ternary.rb
code-ruby-0.8.2 lib/code/node/ternary.rb
code-ruby-0.8.1 lib/code/node/ternary.rb
code-ruby-0.8.0 lib/code/node/ternary.rb
code-ruby-0.7.8 lib/code/node/ternary.rb
code-ruby-0.7.7 lib/code/node/ternary.rb
code-ruby-0.7.6 lib/code/node/ternary.rb
code-ruby-0.7.5 lib/code/node/ternary.rb
code-ruby-0.7.4 lib/code/node/ternary.rb