Class: RubyJsonParser::AST::ObjectLiteralNode

Inherits:
Node
  • Object
show all
Defined in:
lib/ruby_json_parser/ast.rb

Overview

Represents an object literal eg. ‘{ “foo”: 123 }`

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pairsObject (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_sObject



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