Class: Array
- Includes:
- NRSER::Ext::Tree
- Defined in:
- lib/nrser/core_ext/array.rb
Direct Known Subclasses
NRSER::Lines, NRSER::Log::Formatters::Mixin::Tokens, NRSER::RSpex::List
Instance Method Summary collapse
-
#ellipsis(*args) ⇒ Object
Calls NRSER.ellipsis on ‘self`.
- #extract!(&block) ⇒ Object
-
#rest ⇒ Array
New array consisting of all elements after the first (which may be none, resulting in an empty array).
-
#to_chainer(publicly: true) ⇒ Object
See NRSER.chainer.
-
#to_digger ⇒ Proc
Returns a lambda that calls accepts a single arg and calls ‘#dig` on it with the elements of this array as arguments.
-
#to_message ⇒ NRSER::Message
(also: #to_m)
Creates a new NRSER::Message from the array.
-
#to_pair ⇒ Array
Checks that length is 2 and returns ‘self`.
-
#to_sender(publicly: true) ⇒ Proc
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`).
Methods included from NRSER::Ext::Tree
#each_branch, #leaves, #map_branches, #map_leaves, #map_tree
Instance Method Details
#ellipsis(*args) ⇒ Object
Calls NRSER.ellipsis on ‘self`.
20 21 22 |
# File 'lib/nrser/core_ext/array.rb', line 20 def ellipsis *args NRSER.ellipsis self, *args end |
#extract!(&block) ⇒ Object
14 15 16 |
# File 'lib/nrser/core_ext/array.rb', line 14 def extract! &block NRSER.extract_from_array! self, &block end |
#rest ⇒ Array
Returns new array consisting of all elements after the first (which may be none, resulting in an empty array).
9 10 11 |
# File 'lib/nrser/core_ext/array.rb', line 9 def rest NRSER.rest self end |
#to_chainer(publicly: true) ⇒ Object
See NRSER.chainer.
91 92 93 |
# File 'lib/nrser/core_ext/array.rb', line 91 def to_chainer publicly: true NRSER.chainer self, publicly: publicly end |
#to_digger ⇒ Proc
I wanted to use ‘#to_proc` so that you could use `&[:id]`, but unary `&` doesn’t invoke refinements, and I don’t really want to monkey-patch anything, especially something as core as ‘#to_proc` and `Array`.
Returns a lambda that calls accepts a single arg and calls ‘#dig` on it with the elements of this array as arguments.
116 117 118 |
# File 'lib/nrser/core_ext/array.rb', line 116 def to_digger NRSER::Message.new( :dig, *self ).to_proc end |
#to_message ⇒ NRSER::Message Also known as: to_m
Creates a new NRSER::Message from the array.
59 60 61 |
# File 'lib/nrser/core_ext/array.rb', line 59 def NRSER::Message.new *self end |
#to_pair ⇒ Array
Checks that length is 2 and returns ‘self`.
36 37 38 39 40 41 42 43 |
# File 'lib/nrser/core_ext/array.rb', line 36 def to_pair unless length == 2 raise TypeError, "Array is not of length 2: #{ self.inspect }" end self end |
#to_sender(publicly: true) ⇒ Proc
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_proc publicly: boolean
84 85 86 |
# File 'lib/nrser/core_ext/array.rb', line 84 def to_sender publicly: true .to_proc publicly: publicly end |