class Array
Public Instance Methods
ellipsis(*args)
click to toggle source
Calls {NRSER.ellipsis} on `self`.
# File lib/nrser/core_ext/array.rb, line 22 def ellipsis *args NRSER.ellipsis self, *args end
extract!(&block)
click to toggle source
# File lib/nrser/core_ext/array.rb, line 16 def extract! &block NRSER.extract_from_array! self, &block end
rest()
click to toggle source
@return [Array]
new array consisting of all elements after the first (which may be none, resulting in an empty array).
# File lib/nrser/core_ext/array.rb, line 11 def rest NRSER.rest self end
to_chainer(publicly: true)
click to toggle source
See {NRSER.chainer}.
# File lib/nrser/core_ext/array.rb, line 93 def to_chainer publicly: true NRSER.chainer self, publicly: publicly end
to_digger()
click to toggle source
Old name for {#to_proc}.
@deprecated
# File lib/nrser/core_ext/array.rb, line 102 def to_digger NRSER.logger.deprecated \ method: "#{ self.class.name }##{ __method__ }", alternative: "#{ self.class.name }#to_proc" to_proc end
to_message()
click to toggle source
Creates a new {NRSER::Message} from the array.
@example
message = [:fetch, :x].to_message message.send_to x: 'ex', y: 'why?' # => 'ex'
@return [NRSER::Message]
# File lib/nrser/core_ext/array.rb, line 61 def to_message NRSER::Message.new *self end
Also aliased as: to_m
to_pair()
click to toggle source
Checks that length is 2 and returns `self`.
@return [Array]
Array of length 2
@raise [TypeError]
If length is not 2.
# File lib/nrser/core_ext/array.rb, line 38 def to_pair unless length == 2 raise TypeError, "Array is not of length 2: #{ self.inspect }" end self end
to_proc()
click to toggle source
Returns a lambda that calls accepts a single arg and calls either:
-
`#[self.first]` if this array has only one entry.
-
`#dig( *self )` if this array has more than one entry.
@example
list = [{id: 1, name: "Neil"}, {id: 2, name: "Mica"}] list.assoc_by &[:id] # => { # 1 => {id: 1, name: "Neil"}, # 2 => {id: 2, name: "Mica"}, # }
@return [Proc]
Lambda proc that accepts a single argument and calls `#[]` or `#dig with this array's contents as the arguments.
# File lib/nrser/core_ext/array/to_proc.rb, line 22 def to_proc method_name = case count when 0 raise NRSER::CountError.new \ "Can not create getter proc from empty array", value: self, expected: '> 0', count: count when 1 :[] else :dig end NRSER::Message.new( method_name, *self ).to_proc end
to_sender(publicly: true)
click to toggle source
Create a {Proc} that accepts a single `receiver` and provides this array's entries as the arguments to `#public_send` (or `#send` if the `publicly` option is `false`).
Equivalent to
to_message.to_proc publicly: boolean
@example
[:fetch, :x].sender.call x: 'ex' # => 'ex'
@param [Boolean] publicly
When `true`, uses `#public_send` in liu of `#send`.
@return [Proc]
# File lib/nrser/core_ext/array.rb, line 86 def to_sender publicly: true to_message.to_proc publicly: publicly end