Class: JSON5::ObjectValue
- Inherits:
-
Object
- Object
- JSON5::ObjectValue
- Defined in:
- lib/json5/object_value.rb
Defined Under Namespace
Classes: Member
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Returns the value of attribute members.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(members) ⇒ ObjectValue
constructor
A new instance of ObjectValue.
- #to_h ⇒ Object
Constructor Details
#initialize(members) ⇒ ObjectValue
Returns a new instance of ObjectValue.
9 10 11 12 |
# File 'lib/json5/object_value.rb', line 9 def initialize(members) @members = members.map { |key, value| Member.new(key, value) }.freeze freeze end |
Instance Attribute Details
#members ⇒ Object (readonly)
Returns the value of attribute members.
7 8 9 |
# File 'lib/json5/object_value.rb', line 7 def members @members end |
Instance Method Details
#[](key) ⇒ Object
14 15 16 17 |
# File 'lib/json5/object_value.rb', line 14 def [](key) member = members.reverse_each.find { |candidate| candidate.key == key } member&.value end |
#each(&block) ⇒ Object
19 20 21 22 |
# File 'lib/json5/object_value.rb', line 19 def each(&block) return enum_for(__method__) unless block members.each(&block) end |
#to_h ⇒ Object
24 25 26 |
# File 'lib/json5/object_value.rb', line 24 def to_h members.to_h { |member| [member.key, member.value] } end |