Sha256: cbea7218455a0035f001517ff3e8616c3dc6bb51989c7f0fedf01b7de421255d

Contents?: true

Size: 715 Bytes

Versions: 3

Compression:

Stored size: 715 Bytes

Contents

class BlocklyInterpreter::CoreBlocks::ArithmeticOperatorBlock < BlocklyInterpreter::Block
  self.block_type = :math_arithmetic

  def value(execution_context)
    a = values['A'].value(execution_context)
    b = values['B'].value(execution_context)

    case fields['OP'].to_s.upcase
    when 'ADD' then a + b
    when 'MINUS' then a - b
    when 'MULTIPLY' then a * b
    when 'DIVIDE' then a / b
    when 'POWER' then a ** b
    end
  end

  module DSLMethods
    def math_arithmetic(op, a = nil, b = nil, &proc)
      @blocks << BlocklyInterpreter::DSL::BinaryOperationBlockBuilder.new("math_arithmetic", op, a, b).tap do |builder|
        builder.instance_exec(&proc) if block_given?
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blockly_interpreter-0.3.0 lib/blockly_interpreter/core_blocks/arithmetic_operator_block.rb
blockly_interpreter-0.2.1 lib/blockly_interpreter/core_blocks/arithmetic_operator_block.rb
blockly_interpreter-0.2.0 lib/blockly_interpreter/core_blocks/arithmetic_operator_block.rb