Class: BlocklyInterpreter::ExtensionBlocks::SwitchBlock::Conditional

Inherits:
Object
  • Object
show all
Defined in:
lib/blockly_interpreter/extension_blocks/switch_block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(switch_block, num) ⇒ Conditional

Returns a new instance of Conditional.



8
9
10
11
# File 'lib/blockly_interpreter/extension_blocks/switch_block.rb', line 8

def initialize(switch_block, num)
  @predicate_block = switch_block.values["CASE#{num}"]
  @action_block = switch_block.statements["DO#{num}"]
end

Instance Attribute Details

#action_blockObject (readonly)

Returns the value of attribute action_block.



6
7
8
# File 'lib/blockly_interpreter/extension_blocks/switch_block.rb', line 6

def action_block
  @action_block
end

#predicate_blockObject (readonly)

Returns the value of attribute predicate_block.



6
7
8
# File 'lib/blockly_interpreter/extension_blocks/switch_block.rb', line 6

def predicate_block
  @predicate_block
end

Instance Method Details

#execute_statement(execution_context) ⇒ Object



17
18
19
# File 'lib/blockly_interpreter/extension_blocks/switch_block.rb', line 17

def execute_statement(execution_context)
  execution_context.execute(action_block)
end

#matches?(value, execution_context) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/blockly_interpreter/extension_blocks/switch_block.rb', line 13

def matches?(value, execution_context)
  predicate_block.value(execution_context) == value
end