Class: BlocklyInterpreter::CoreBlocks::ListsCreateWithBlock

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

Constructor Details

This class inherits a constructor from BlocklyInterpreter::Block

Instance Method Details

#item_countObject



5
6
7
# File 'lib/blockly_interpreter/core_blocks/lists_create_with_block.rb', line 5

def item_count
  @item_count ||= mutation.try(:[], 'items').try(:to_i) || 0
end

#itemsObject



9
10
11
12
13
# File 'lib/blockly_interpreter/core_blocks/lists_create_with_block.rb', line 9

def items
  @items ||= (0...item_count).map do |i|
    values["ADD#{i}"]
  end.compact
end

#to_dslObject



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

def to_dsl
  item_dsls = items.map { |item| method_call_with_possible_block("item", "", item) }
  method_call_with_possible_block("lists_create_with", "", item_dsls)
end

#value(execution_context) ⇒ Object



15
16
17
# File 'lib/blockly_interpreter/core_blocks/lists_create_with_block.rb', line 15

def value(execution_context)
  items.map { |item| item.value(execution_context) }
end