Class: BlocklyInterpreter::CoreBlocks::ProcedureBlock

Inherits:
Block
  • Object
show all
Includes:
DSLGenerator
Defined in:
lib/blockly_interpreter/core_blocks/procedure_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 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, #value

Constructor Details

This class inherits a constructor from BlocklyInterpreter::Block

Instance Method Details

#arg_hash(parameters) ⇒ Object



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

def arg_hash(parameters)
  Hash[arg_names.zip(parameters)]
end

#arg_namesObject



8
9
10
# File 'lib/blockly_interpreter/core_blocks/procedure_block.rb', line 8

def arg_names
  @arg_names ||= (mutation && mutation.css('> arg').map { |arg| arg['name'] }) || []
end

#arg_values(execution_context) ⇒ Object



12
13
14
15
16
# File 'lib/blockly_interpreter/core_blocks/procedure_block.rb', line 12

def arg_values(execution_context)
  (0...arg_names.size).map do |arg_num|
    values["ARG#{arg_num}"].value(execution_context)
  end
end

#args_dslObject



18
19
20
21
22
# File 'lib/blockly_interpreter/core_blocks/procedure_block.rb', line 18

def args_dsl
  arg_names.each_with_index.map do |arg_name, i|
    method_call_with_possible_block("arg", arg_name.inspect, values["ARG#{i}"])
  end.compact
end

#to_dslObject



24
25
26
# File 'lib/blockly_interpreter/core_blocks/procedure_block.rb', line 24

def to_dsl
  method_call_with_possible_block "#{self.class.block_type}", procedure_name.inspect, args_dsl
end