Class: Platform::IEL::StdLibAssoc
- Inherits:
-
Object
- Object
- Platform::IEL::StdLibAssoc
- Defined in:
- lib/introhive_expression_language/iel/std_lib_assoc.rb
Class Method Summary collapse
-
.assoc_contains(associative_array, key) ⇒ Object
TODO this can be reused as a defining_context with tests.
- .assoc_get(associative_array, keys) ⇒ Object
- .declare(defining_context) ⇒ Object
Class Method Details
.assoc_contains(associative_array, key) ⇒ Object
TODO this can be reused as a defining_context with tests
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/introhive_expression_language/iel/std_lib_assoc.rb', line 33 def assoc_contains(associative_array, key) match = associative_array.value.find do |kv_node| kv_node.kind == :list && kv_node.value.size >= 2 && kv_node.value.first == key end if match SexpParser::Node.boolean(true) else SexpParser::Node.boolean(false) end end |
.assoc_get(associative_array, keys) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/introhive_expression_language/iel/std_lib_assoc.rb', line 13 def assoc_get(associative_array, keys) match = nil # Still have to support single keys - Strings and symbols. Convert them to a list so we can go through logic normally keys = SexpParser::Node.list([keys]) unless keys.kind == :list keys.value.each do |k| match = associative_array.value.find do |kv_node| kv_node.kind == :list && kv_node.value.size >= 2 && kv_node.value.first == k end break if match.nil? associative_array = match.value[1] end if match match.value[1] else SexpParser::Node.nil end end |
.declare(defining_context) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/introhive_expression_language/iel/std_lib_assoc.rb', line 6 def declare(defining_context) StdLibList.declare(defining_context) declare_assoc(defining_context) declare_assoc_get(defining_context) # declare_assoc_let(defining_context) # This needs to be reimplemented to ensure immutability of data structures end |