Module: JSI::Base::Enumerable

Includes:
Enumerable
Included in:
ArrayNode, HashNode
Defined in:
lib/jsi/base/node.rb

Instance Method Summary collapse

Instance Method Details

#to_a(**kw) ⇒ Array Also known as: entries

an Array containing each item in this JSI.

Parameters:

  • kw

    keyword arguments are passed to JSI::Base#[] - see its keyword params

Returns:

  • (Array)


11
12
13
14
15
16
17
18
19
20
# File 'lib/jsi/base/node.rb', line 11

def to_a(**kw)
  # TODO remove eventually (keyword argument compatibility)
  # discard when all supported ruby versions Enumerable#to_a delegate keywords to #each (3.0.1 breaks; 2.7.x warns)
  # https://bugs.ruby-lang.org/issues/18289
  ary = []
  each(**kw) do |e|
    ary << e
  end
  ary.freeze
end