Module: Enumerable
- Included in:
- Ruber::AnnotationModel, Ruber::ComponentManager, Ruber::DocumentList, Ruber::ProjectFilesList, Ruber::ProjectList
- Defined in:
- lib/ruber/utils.rb
Instance Method Summary collapse
-
#find! { ... } ⇒ Object?
(also: #find_and_map)
Finds the first element for which the block returns a true value and returns the value of the block.
Instance Method Details
#find! { ... } ⇒ Object? Also known as: find_and_map
Finds the first element for which the block returns a true value and returns the value of the block
It works like @Enumerable#find@, but, instead of returning the element for which the block returned a true value, it returns the value returned by the block. if the block returns nil or false for all elements
[1, 2, 3, 4].find{|i| 2*i if i > 2}
> 6 #(3*2)
307 308 309 310 311 312 313 |
# File 'lib/ruber/utils.rb', line 307 def find! each do |obj| res = yield obj return res if res end nil end |