Class: BlocklyInterpreter::CoreBlocks::ProcedureBlock
- Includes:
- DSLGenerator
- Defined in:
- lib/blockly_interpreter/core_blocks/procedure_block.rb
Direct Known Subclasses
ProceduresCallNoReturnBlock, ProceduresCallReturnBlock, ProceduresDefNoReturnBlock, ProceduresDefReturnBlock
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
- #arg_hash(parameters) ⇒ Object
- #arg_names ⇒ Object
- #arg_values(execution_context) ⇒ Object
- #args_dsl ⇒ Object
- #to_dsl ⇒ Object
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_names ⇒ Object
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_dsl ⇒ Object
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_dsl ⇒ Object
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 |