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
-
#inspect ⇒ String
Basically the same #inspect as Array, but has the class name and, if responsive, self's #object_group_text.
-
#pretty_print(q) ⇒ void
pretty-prints a representation this node to the given printer.
-
#to_s ⇒ String
See #inspect.
Instance Method Details
#inspect ⇒ String
219 220 221 222 |
# File 'lib/jsi/typelike_modules.rb', line 219 def inspect object_group_str = JSI.object_group_str(respond_to?(:object_group_text) ? object_group_text : []) "\#[<#{self.class}#{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
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/jsi/typelike_modules.rb', line 231 def pretty_print(q) q.instance_exec(self) do |obj| object_group_str = JSI.object_group_str(obj.respond_to?(:object_group_text) ? obj.object_group_text : []) text "\#[<#{obj.class}#{object_group_str}>" group_sub { nest(2) { breakable(obj.any? { true } ? ' ' : '') seplist(obj, nil, :each) { |e| pp e } } } breakable '' text ']' end end |
#to_s ⇒ String
225 226 227 |
# File 'lib/jsi/typelike_modules.rb', line 225 def to_s inspect end |