Class: RubyJsonParser::AST::ObjectLiteralNode
- Defined in:
- lib/ruby_json_parser/ast.rb
Overview
Represents an object literal eg. ‘{ “foo”: 123 }`
Instance Attribute Summary collapse
-
#pairs ⇒ Object
readonly
Returns the value of attribute pairs.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(pairs) ⇒ ObjectLiteralNode
constructor
A new instance of ObjectLiteralNode.
- #inspect(indent = 0) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(pairs) ⇒ ObjectLiteralNode
Returns a new instance of ObjectLiteralNode.
172 173 174 |
# File 'lib/ruby_json_parser/ast.rb', line 172 def initialize(pairs) @pairs = pairs end |
Instance Attribute Details
#pairs ⇒ Object (readonly)
Returns the value of attribute pairs.
169 170 171 |
# File 'lib/ruby_json_parser/ast.rb', line 169 def pairs @pairs end |
Instance Method Details
#==(other) ⇒ Object
177 178 179 180 181 |
# File 'lib/ruby_json_parser/ast.rb', line 177 def ==(other) return false unless other.is_a?(ObjectLiteralNode) pairs == other.pairs end |
#inspect(indent = 0) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/ruby_json_parser/ast.rb', line 198 def inspect(indent = 0) buff = String.new buff << "#{INDENT_UNIT * indent}(object" @pairs.each do |pair| buff << "\n" buff << pair.inspect(indent + 1) end buff << ')' buff end |
#to_s ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ruby_json_parser/ast.rb', line 184 def to_s buff = String.new buff << '{' @pairs.each.with_index do |pair, i| buff << ', ' if i > 0 buff << pair.to_s end buff << '}' buff end |