Module: JSI::Arraylike
- Included in:
- BaseArray, JSON::ArrayNode
- 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
Returns basically the same #inspect as Array, but has the class name and, if responsive, self's #object_group_text.
191 192 193 194 |
# File 'lib/jsi/typelike_modules.rb', line 191 def inspect object_group_text = respond_to?(:object_group_text) ? ' ' + self.object_group_text : '' "\#[<#{self.class}#{object_group_text}>#{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
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/jsi/typelike_modules.rb', line 203 def pretty_print(q) q.instance_exec(self) do |obj| object_group_text = obj.respond_to?(:object_group_text) ? ' ' + obj.object_group_text : '' text "\#[<#{obj.class}#{object_group_text}>" group_sub { nest(2) { breakable(obj.any? { true } ? ' ' : '') seplist(obj, nil, :each) { |e| pp e } } } breakable '' text ']' end end |
#to_s ⇒ String
Returns see #inspect.
197 198 199 |
# File 'lib/jsi/typelike_modules.rb', line 197 def to_s inspect end |