Module: JSI::Arraylike

Included in:
PathedArrayNode
Defined in:
lib/jsi/typelike_modules.rb

Overview

a module of methods for objects which behave like Array but are not Array.

this module is intended to be internal to JSI. no guarantees or API promises are made for non-JSI classes including this module.

Constant Summary collapse

SAFE_INDEX_ONLY_METHODS =

methods which do not need to access the element.

%w(each_index empty? length size)
SAFE_INDEX_ELEMENT_METHODS =

there are some ambiguous ones that are omitted, like #sort, #map / #collect.

%w(| & * + - <=> abbrev assoc at bsearch bsearch_index combination compact count cycle dig drop drop_while fetch find_index first include? index join last pack permutation product reject repeated_combination repeated_permutation reverse reverse_each rindex rotate sample select shelljoin shuffle slice sort take take_while transpose uniq values_at zip)
DESTRUCTIVE_METHODS =
%w(<< clear collect! compact! concat delete delete_at delete_if fill flatten! insert keep_if map! pop push reject! replace reverse! rotate! select! shift shuffle! slice! sort! sort_by! uniq! unshift)
SAFE_METHODS =
SAFE_INDEX_ONLY_METHODS | SAFE_INDEX_ELEMENT_METHODS

Instance Method Summary collapse

Instance Method Details

#inspectString Also known as: to_s

Returns basically the same #inspect as Array, but has the class name and, if responsive, self's #object_group_text.

Returns:

  • (String)

    basically the same #inspect as Array, but has the class name and, if responsive, self's #object_group_text



216
217
218
219
# File 'lib/jsi/typelike_modules.rb', line 216

def inspect
  object_group_str = (respond_to?(:object_group_text) ? object_group_text : [self.class]).join(' ')
  "\#[<#{object_group_str}>#{empty? ? '' : ' '}#{self.map { |e| e.inspect }.join(', ')}]"
end

#pretty_print(q) ⇒ void

This method returns an undefined value.

pretty-prints a representation this node to the given printer



225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/jsi/typelike_modules.rb', line 225

def pretty_print(q)
  object_group_str = (respond_to?(:object_group_text) ? object_group_text : [self.class]).join(' ')
  q.text "\#[<#{object_group_str}>"
  q.group_sub {
    q.nest(2) {
      q.breakable(any? { true } ? ' ' : '')
      q.seplist(self, nil, :each) { |e|
        q.pp e
      }
    }
  }
  q.breakable ''
  q.text ']'
end