Class: JSI::JSON::ArrayNode

Inherits:
Node
  • Object
show all
Includes:
Enumerable, Arraylike
Defined in:
lib/jsi/json/node.rb

Overview

a JSI::JSON::Node whose content is Array-like (responds to #to_ary) and includes Array methods from Arraylike

Constant Summary

Constants included from Arraylike

Arraylike::DESTRUCTIVE_METHODS, Arraylike::SAFE_INDEX_ELEMENT_METHODS, Arraylike::SAFE_INDEX_ONLY_METHODS, Arraylike::SAFE_METHODS

Instance Attribute Summary

Attributes inherited from Node

#document, #path, #pointer

Instance Method Summary collapse

Methods included from Arraylike

#inspect, #pretty_print, #to_s

Methods inherited from Node

#[], #[]=, #content, #deref, #document_node, #fingerprint, #fragment, #initialize, #inspect, #modified_copy, new_by_type, new_doc, #object_group_text, #parent_node, #pointer_path, #pretty_print

Methods included from FingerprintHash

#==, #hash

Constructor Details

This class inherits a constructor from JSI::JSON::Node

Instance Method Details

#as_json(*opt) ⇒ Object

returns a jsonifiable representation of this node's content



283
284
285
# File 'lib/jsi/json/node.rb', line 283

def as_json(*opt) # needs redefined after including Enumerable
  Typelike.as_json(content, *opt)
end

#eachObject

iterates over each element in the same manner as Array#each



268
269
270
271
272
# File 'lib/jsi/json/node.rb', line 268

def each
  return to_enum(__method__) { (content.respond_to?(:size) ? content : content.to_ary).size } unless block_given?
  (content.respond_to?(:each_index) ? content : content.to_ary).each_index { |i| yield self[i] }
  self
end

#to_aryObject

the content of this ArrayNode, as an Array



275
276
277
# File 'lib/jsi/json/node.rb', line 275

def to_ary
  to_a
end