Module: Enumerable
- Included in:
- NRSER::Sys::Env::Path
- Defined in:
- lib/nrser/core_ext/enumerable.rb,
lib/nrser/core_ext/enumerable/find_map.rb
Overview
Instance methods to extend Enumerable.
Instance Method Summary collapse
-
#assoc_by(*args, &block) ⇒ Object
See NRSER.assoc_by.
-
#assoc_to(*args, &block) ⇒ Object
See NRSER.assoc_to.
-
#count_by(&block) ⇒ Object
See NRSER.count_by.
- #enumerate_as_values ⇒ Object
-
#find_bounded(bounds, &block) ⇒ Object
See NRSER.find_bounded.
-
#find_map(ifnone = nil, &block) ⇒ nil, ...
Find the first truthy (not ‘nil` or `false`) result of calling `&block` on entries.
-
#find_only(&block) ⇒ Object
See NRSER.find_only.
-
#only(**options) ⇒ Object
Calls NRSER.only on ‘self`.
-
#only! ⇒ Object
See NRSER.only!.
-
#slice?(*args, &block) ⇒ Boolean
See NRSER.slice?.
-
#try_find(&block) ⇒ Object
See NRSER.try_find.
Instance Method Details
#assoc_by(*args, &block) ⇒ Object
See NRSER.assoc_by
22 23 24 |
# File 'lib/nrser/core_ext/enumerable.rb', line 22 def assoc_by *args, &block NRSER.assoc_by self, *args, &block end |
#assoc_to(*args, &block) ⇒ Object
See NRSER.assoc_to
28 29 30 |
# File 'lib/nrser/core_ext/enumerable.rb', line 28 def assoc_to *args, &block NRSER.assoc_to self, *args, &block end |
#count_by(&block) ⇒ Object
See NRSER.count_by
52 53 54 |
# File 'lib/nrser/core_ext/enumerable.rb', line 52 def count_by &block NRSER.count_by self, &block end |
#enumerate_as_values ⇒ Object
34 35 36 |
# File 'lib/nrser/core_ext/enumerable.rb', line 34 def enumerate_as_values NRSER.enumerate_as_values self end |
#find_bounded(bounds, &block) ⇒ Object
10 11 12 |
# File 'lib/nrser/core_ext/enumerable.rb', line 10 def find_bounded bounds, &block NRSER.find_bounded self, bounds, &block end |
#find_map(ifnone = nil, &block) ⇒ nil, ...
Find the first truthy (not ‘nil` or `false`) result of calling `&block` on entries.
Like #find, accepts an optional ‘ifnone` procedure to call if no match is found.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nrser/core_ext/enumerable/find_map.rb', line 44 def find_map ifnone = nil, &block each do |entry| if result = block.call( entry ) # Found a match, short-circuit return result end end # No matches, return `ifnone` ifnone.call if ifnone end |
#find_only(&block) ⇒ Object
See NRSER.find_only
16 17 18 |
# File 'lib/nrser/core_ext/enumerable.rb', line 16 def find_only &block NRSER.find_only self, &block end |
#only(**options) ⇒ Object
Calls NRSER.only on ‘self`.
40 41 42 |
# File 'lib/nrser/core_ext/enumerable.rb', line 40 def only ** NRSER.only self, ** end |
#only! ⇒ Object
See NRSER.only!
46 47 48 |
# File 'lib/nrser/core_ext/enumerable.rb', line 46 def only! NRSER.only! self end |
#slice?(*args, &block) ⇒ Boolean
See NRSER.slice?
64 65 66 |
# File 'lib/nrser/core_ext/enumerable.rb', line 64 def slice? *args, &block NRSER.slice? self, *args, &block end |
#try_find(&block) ⇒ Object
See NRSER.try_find
58 59 60 |
# File 'lib/nrser/core_ext/enumerable.rb', line 58 def try_find &block NRSER.try_find self, &block end |