Module: JSI::Base::ArrayNode
- Includes:
- Enumerable, Util::Arraylike
- Defined in:
- lib/jsi/base/node.rb
Overview
module extending a JSI::Base object when its instance (its #jsi_node_content)
is an Array (or responds to #to_ary
)
Constant Summary
Constants included from Util::Arraylike
Util::Arraylike::DESTRUCTIVE_METHODS, Util::Arraylike::SAFE_INDEX_ELEMENT_METHODS, Util::Arraylike::SAFE_INDEX_ONLY_METHODS, Util::Arraylike::SAFE_METHODS
Instance Method Summary collapse
-
#each(**kw) {|Object| ... } ⇒ self, Enumerator
yields each array element of this node.
-
#jsi_node_content_ary_pubsend(method_name, *a, **kw, &b) ⇒ Object
invokes the method with the given name on the jsi_node_content (if defined) or its #to_ary.
-
#to_ary(**kw) ⇒ Array
an array, the same size as the instance array, in which the element at each index is the result of #[].
Methods included from Util::Arraylike
#assoc, #inspect, #pretty_print, #rassoc
Methods included from Enumerable
Instance Method Details
#each(**kw) {|Object| ... } ⇒ self, Enumerator
yields each array element of this node.
each yielded element is the result of JSI::Base#[] for each index of the instance array.
returns an Enumerator if no block is given.
124 125 126 127 128 |
# File 'lib/jsi/base/node.rb', line 124 def each(**kw, &block) return to_enum(__method__, **kw) { jsi_node_content_ary_pubsend(:size) } unless block jsi_node_content_ary_pubsend(:each_index) { |i| yield(self[i, **kw]) } self end |
#jsi_node_content_ary_pubsend(method_name, *a, **kw, &b) ⇒ Object
invokes the method with the given name on the jsi_node_content (if defined) or its #to_ary
146 147 148 149 150 151 152 |
# File 'lib/jsi/base/node.rb', line 146 def jsi_node_content_ary_pubsend(method_name, *a, &b) if jsi_node_content.respond_to?(method_name) jsi_node_content.public_send(method_name, *a, &b) else jsi_node_content.to_ary.public_send(method_name, *a, &b) end end |
#to_ary(**kw) ⇒ Array
an array, the same size as the instance array, in which the element at each index is the result of JSI::Base#[].
134 135 136 |
# File 'lib/jsi/base/node.rb', line 134 def to_ary(**kw) to_a(**kw) end |