README.md in ect-1.0.0 vs README.md in ect-1.1.0
- old
+ new
@@ -1,9 +1,9 @@
# ect
-[![Gem Version](https://badge.fury.io/rb/et-orbi.svg)](http://badge.fury.io/rb/ect)
+[![Gem Version](https://badge.fury.io/rb/ect.svg)](http://badge.fury.io/rb/ect)
Ruby methods ending in `ect`.
The subject of last part of a [lightning talk](https://speakerdeck.com/jmettraux/ruby-methods-in-ect-hiroshima-dot-rb-number-058) for [Hiroshima.rb #058](https://hiroshimarb.connpass.com/event/65459/).
@@ -32,20 +32,27 @@
> deflect |dɪˈflɛkt|
>
> ORIGIN mid 16th cent.: from Latin deflectere, from de- ‘away from’ + flectere ‘to bend’.
-A very simple `yield(self)` (in Ruby 2.5.x it could thus become an alias to `#yiel_self`).
+A very simple `yield(self)` (in Ruby 2.5.x it could thus become an alias to `#yield_self`).
Passes the instance to the block, returns the result of the block. Change of direction.
```ruby
[ animals_list_1, animals_list_2 ]
.deflect { |a, b| a.include?('mole') ? a : b }
.collect(&:capitalize)
```
+```ruby
+user = DB[:users]
+ .select(:id, :name)
+ .deflect { |x| id ? x.where(id: id) : x.where(name: name) }
+ .first
+```
+
## Enumerable
### Enumerable#bisect
> bisect |bʌɪˈsɛkt|
@@ -88,9 +95,24 @@
end }
p a0 # => [ 1, 3, 4, 6, 7, 9, 10, 12, 13 ]
p a1 # => nil
p a2 # => [ 2, 5, 8, 11, 14 ]
+```
+
+### Enumerable#elect
+
+> elect |əˈlekt|
+>
+> ORIGIN late Middle English: from Latin elect- ‘picked out’, from the verb eligere, from e- (variant of ex-) ‘out’ + legere ‘to pick’.
+
+Like a `find`, but yields the result of the block instead of the matching element.
+
+```ruby
+a = [ { a: 1 }, { b: 2 }, { c: 3 } ]
+
+a.elect { |e| e[:b] } # => 2
+a.elect { |e| e[:z] } # => nil
```
## LICENSE