Module: Scorpio::Arraylike

Includes:
Enumerable
Included in:
JSON::ArrayNode, SchemaInstanceBaseArray
Defined in:
lib/scorpio/typelike_modules.rb

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

#inspectObject



142
143
144
145
# File 'lib/scorpio/typelike_modules.rb', line 142

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

#pretty_print(q) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/scorpio/typelike_modules.rb', line 151

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.to_s}#{object_group_text}>"
    group_sub {
      nest(2) {
        breakable(obj.any? { true } ? ' ' : '')
        seplist(obj, nil, :each) { |e|
          pp e
        }
      }
    }
    breakable ''
    text ']'
  end
end

#to_sObject



147
148
149
# File 'lib/scorpio/typelike_modules.rb', line 147

def to_s
  inspect
end