Class: Ruby::Rego::ObjectValue
Overview
Represents an object value.
Constant Summary collapse
- TYPE_NAME =
"object"
Instance Attribute Summary
Attributes inherited from Value
Instance Method Summary collapse
-
#fetch(key) ⇒ Value
Fetch a value by key.
-
#fetch_reference(key) ⇒ Value
Resolve a reference for an object.
-
#initialize(pairs) ⇒ ObjectValue
constructor
Create an object value.
-
#to_ruby ⇒ Hash<Object, Object>
Convert the object 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(pairs) ⇒ ObjectValue
Create an object value.
337 338 339 340 |
# File 'lib/ruby/rego/value.rb', line 337 def initialize(pairs) @values = normalize_pairs(pairs) super(@values) end |
Instance Method Details
#fetch(key) ⇒ Value
Fetch a value by key.
394 395 396 397 398 399 400 |
# File 'lib/ruby/rego/value.rb', line 394 def fetch(key) return @values[key] if @values.key?(key) return fetch_numeric(key) if key.is_a?(Numeric) return fetch_by_symbol_key(key) if key.is_a?(Symbol) UndefinedValue.new end |
#fetch_reference(key) ⇒ Value
Resolve a reference for an object.
413 414 415 |
# File 'lib/ruby/rego/value.rb', line 413 def fetch_reference(key) fetch(key) end |
#to_ruby ⇒ Hash<Object, Object>
Convert the object back to Ruby.
425 426 427 |
# File 'lib/ruby/rego/value.rb', line 425 def to_ruby @values.transform_values(&:to_ruby) end |