Class: Ruby::Rego::ArrayValue
Overview
Represents an array value.
Constant Summary collapse
- TYPE_NAME =
"array"
Instance Attribute Summary
Attributes inherited from Value
Instance Method Summary collapse
-
#fetch_index(index) ⇒ Value
Fetch an element by index.
-
#fetch_reference(key) ⇒ Value
Resolve a reference for an array.
-
#initialize(elements) ⇒ ArrayValue
constructor
Create an array value.
-
#to_ruby ⇒ Array<Object>
Convert the array back to Ruby.
Methods inherited from Value
#==, from_ruby, #hash, #object_key, #truthy?, #type_name, #undefined?
Constructor Details
#initialize(elements) ⇒ ArrayValue
Create an array value.
238 239 240 241 |
# File 'lib/ruby/rego/value.rb', line 238 def initialize(elements) @elements = elements.map { |element| Value.from_ruby(element) } super(@elements) end |
Instance Method Details
#fetch_index(index) ⇒ Value
Fetch an element by index.
247 248 249 250 251 |
# File 'lib/ruby/rego/value.rb', line 247 def fetch_index(index) return UndefinedValue.new unless index.is_a?(Integer) @elements[index] || UndefinedValue.new end |
#fetch_reference(key) ⇒ Value
Resolve a reference for an array.
257 258 259 |
# File 'lib/ruby/rego/value.rb', line 257 def fetch_reference(key) fetch_index(key) end |
#to_ruby ⇒ Array<Object>
Convert the array back to Ruby.
264 265 266 |
# File 'lib/ruby/rego/value.rb', line 264 def to_ruby @elements.map(&:to_ruby) end |