Class: RubyJsonParser::AST::ArrayLiteralNode
- Defined in:
- lib/ruby_json_parser/ast.rb
Overview
Represents an object literal eg. ‘[1, “foo”]`
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(elements) ⇒ ArrayLiteralNode
constructor
A new instance of ArrayLiteralNode.
- #inspect(indent = 0) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(elements) ⇒ ArrayLiteralNode
Returns a new instance of ArrayLiteralNode.
273 274 275 |
# File 'lib/ruby_json_parser/ast.rb', line 273 def initialize(elements) @elements = elements end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
270 271 272 |
# File 'lib/ruby_json_parser/ast.rb', line 270 def elements @elements end |
Instance Method Details
#==(other) ⇒ Object
278 279 280 281 282 |
# File 'lib/ruby_json_parser/ast.rb', line 278 def ==(other) return false unless other.is_a?(ArrayLiteralNode) elements == other.elements end |
#inspect(indent = 0) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/ruby_json_parser/ast.rb', line 299 def inspect(indent = 0) buff = String.new buff << "#{INDENT_UNIT * indent}(array" @elements.each do |element| buff << "\n" buff << element.inspect(indent + 1) end buff << ')' buff end |
#to_s ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/ruby_json_parser/ast.rb', line 285 def to_s buff = String.new buff << '[' @elements.each.with_index do |element, i| buff << ', ' if i > 0 buff << element.to_s end buff << ']' buff end |