Class: Array
Direct Known Subclasses
Instance Method Summary collapse
- #apply(to) ⇒ Object
- #filled? ⇒ Boolean (also: #notempty?, #full?, #unempty?)
- #hmap(&block) ⇒ Object
- #ll?(method, *args) ⇒ Boolean
- #mall?(op, &block) ⇒ Boolean
- #mavg(&block) ⇒ Object
- #meach(*args, &block) ⇒ Object
- #mmid(&sorter) ⇒ Object
- #msum(initial = 0.0, op = :+, &block) ⇒ Object
- #msym ⇒ Object
- #no?(method, *args) ⇒ Boolean
- #ny?(method, *args) ⇒ Boolean
- #realize! ⇒ Object
- #return_first(&block) ⇒ Object (also: #earliest, #first!)
- #sequester!(crush = true) ⇒ Object
- #values ⇒ Object
Instance Method Details
#apply(to) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/ext/array.rb', line 70 def apply(to) map do |m| if m.m? to.send(m) else m.s!.walk(to) end end end |
#filled? ⇒ Boolean Also known as: notempty?, full?, unempty?
9 |
# File 'lib/ext/array.rb', line 9 def filled?() !mt? end |
#hmap(&block) ⇒ Object
104 105 106 |
# File 'lib/ext/array.rb', line 104 def hmap(&block) each.with_object({}, &block) end |
#ll?(method, *args) ⇒ Boolean
22 23 24 |
# File 'lib/ext/array.rb', line 22 def ll?(method, *args) all? { |o| o.send(method, *args) } end |
#mall?(op, &block) ⇒ Boolean
94 95 96 97 98 99 100 101 102 |
# File 'lib/ext/array.rb', line 94 def mall?(op, &block) if op all? { |item| item.send(op) } elsif block all? { |item| item.instance_exec(item, &block) } else all? { |item| item } end end |
#mavg(&block) ⇒ Object
34 35 36 |
# File 'lib/ext/array.rb', line 34 def mavg(&block) msum(&block) / size end |
#meach(*args, &block) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ext/array.rb', line 80 def meach(*args, &block) if block map { |item| instance_exec(item, *args, &block) } elsif args.size == 1 map(&args.first.sym) else #args.each.with_object({}) do |action, o| # o[action.sym] = map(&action.sym) #end method = args.shift map { |item| item.send(method, *args) } end end |
#mmid(&sorter) ⇒ Object
38 39 40 41 |
# File 'lib/ext/array.rb', line 38 def mmid(&sorter) sorted = sort(&sorter) length.odd? ? sorted[length / 2].f! : (sorted[length/2 - 1].f! + sorted[length/2].f!).f! / 2 end |
#msum(initial = 0.0, op = :+, &block) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ext/array.rb', line 26 def msum(initial = 0.0, op = :+, &block) if block inject(initial) { |m, val| m.send(op, block[val]) } else map(&:f!).inject(initial, op) end end |
#msym ⇒ Object
68 |
# File 'lib/ext/array.rb', line 68 def msym() map(&:sym) end |
#no?(method, *args) ⇒ Boolean
18 19 20 |
# File 'lib/ext/array.rb', line 18 def no?(method, *args) none? { |o| o.send(method, *args) } end |
#ny?(method, *args) ⇒ Boolean
14 15 16 |
# File 'lib/ext/array.rb', line 14 def ny?(method, *args) any? { |o| o.send(method, *args) } end |
#realize! ⇒ Object
55 56 57 |
# File 'lib/ext/array.rb', line 55 def realize! empty? ? nil : self end |
#return_first(&block) ⇒ Object Also known as: earliest, first!
59 60 61 62 63 |
# File 'lib/ext/array.rb', line 59 def return_first(&block) returned = nil each { |item| break if (returned = block.call(item)) } returned end |
#sequester!(crush = true) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/ext/array.rb', line 47 def sequester!(crush = true) if crush compact.size <= 1 ? compact.first : self else size <= 1 ? first : self end end |
#values ⇒ Object
43 44 45 |
# File 'lib/ext/array.rb', line 43 def values() self end |