Class: BlocklyInterpreter::CoreBlocks::ProceduresDefReturnBlock

Inherits:
ProcedureBlock show all
Defined in:
lib/blockly_interpreter/core_blocks/procedures_def_return_block.rb

Defined Under Namespace

Modules: DSLMethods

Instance Attribute Summary

Attributes inherited from Block

#block_type, #comment, #comment_pinned, #fields, #is_shadow, #mutation, #next_block, #statements, #values, #x, #y

Instance Method Summary collapse

Methods inherited from ProcedureBlock

#arg_hash, #arg_names, #arg_values, #args_dsl

Methods included from DSLGenerator

#deep_flatten, #formatted_keyword_args, #indent, #keyword_args_without_defaults, #method_call, #method_call_with_block_or_nothing, #method_call_with_possible_block, #start_block_to_dsl, #strip_trailing_whitespace, #timestamp_to_dsl

Methods inherited from Block

#each_block, #execute_statement, #has_comment?, #has_position?, #initialize, #to_xml, #to_xml_element

Constructor Details

This class inherits a constructor from BlocklyInterpreter::Block

Instance Method Details

#procedure_nameObject



4
5
6
# File 'lib/blockly_interpreter/core_blocks/procedures_def_return_block.rb', line 4

def procedure_name
  fields['NAME']
end

#to_dslObject



18
19
20
21
22
23
24
25
# File 'lib/blockly_interpreter/core_blocks/procedures_def_return_block.rb', line 18

def to_dsl
  block_contents = [
    method_call_with_block_or_nothing("body", "", statements['STACK']),
    method_call_with_block_or_nothing("return_value", "", values['RETURN'])
  ]

  method_call_with_possible_block "#{self.class.block_type}", ([procedure_name] + arg_names).map(&:inspect).join(", "), block_contents
end

#value(execution_context) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/blockly_interpreter/core_blocks/procedures_def_return_block.rb', line 8

def value(execution_context)
  execution_context.execute(statements['STACK'])

  if execution_context.terminated
    execution_context.early_return_value
  else
    values['RETURN'].value(execution_context)
  end
end