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
#==, #canonical, canonicalize, canonicalize_each, canonicalize_float, from_ruby, #hash, #object_key, #truthy?, #type_name, #undefined?
Constructor Details
#initialize(elements) ⇒ ArrayValue
Create an array value.
295 296 297 298 |
# File 'lib/ruby/rego/value.rb', line 295 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.
304 305 306 307 308 |
# File 'lib/ruby/rego/value.rb', line 304 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.
314 315 316 |
# File 'lib/ruby/rego/value.rb', line 314 def fetch_reference(key) fetch_index(key) end |
#to_ruby ⇒ Array<Object>
Convert the array back to Ruby.
321 322 323 |
# File 'lib/ruby/rego/value.rb', line 321 def to_ruby @elements.map(&:to_ruby) end |