Module: JSI::PathedArrayNode

Includes:
Arraylike
Included in:
JSON::ArrayNode
Defined in:
lib/jsi/pathed_node.rb

Constant Summary

Constants included from Arraylike

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

Instance Method Summary collapse

Methods included from Arraylike

#inspect, #pretty_print

Instance Method Details

#each {|Object| ... } ⇒ self, Enumerator

yields each array element of this node.

each yielded element is the result of self[index] for each index of our array (see #[]).

returns an Enumerator if no block is given.

Yields:

  • (Object)

    each element of this array node

Returns:

  • (self, Enumerator)


85
86
87
88
89
# File 'lib/jsi/pathed_node.rb', line 85

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

#node_content_ary_pubsend(method_name, *a, &b) ⇒ Object

Returns the result of calling method method_name on the node_content or its #to_ary.

Parameters:

  • method_name (String, Symbol)
  • *a,

    &b are passed to the invocation of method_name

Returns:

  • (Object)

    the result of calling method method_name on the node_content or its #to_ary



102
103
104
105
106
107
108
# File 'lib/jsi/pathed_node.rb', line 102

def node_content_ary_pubsend(method_name, *a, &b)
  if node_content.respond_to?(method_name)
    node_content.public_send(method_name, *a, &b)
  else
    node_content.to_ary.public_send(method_name, *a, &b)
  end
end

#to_aryArray

Returns an array, the same size as the node_content, in which the element at each index is the result of selfindex.

Returns:

  • (Array)

    an array, the same size as the node_content, in which the element at each index is the result of selfindex



93
94
95
# File 'lib/jsi/pathed_node.rb', line 93

def to_ary
  to_a
end