lambda - Secondary Block in Ruby Enumerable -


i can't find called find out more why works , how works, we've found can this:

person = struct.new(:name) people = [person.new('foo'), person.new('bar')] # => [#<struct person name="foo">, #<struct person name="bar">] people.find { |person| person.name == 'baz' } # => nil people.find(->{ [] }) { |person| person.name == 'baz' } # => [] 

i'd think it's of fallthrough block whenever returns nil, perhaps shed light on how works?

from documentation:

find(ifnone = nil) {| obj | block } → obj or nil

find(ifnone = nil) → an_enumerator

passes each entry in enum block. returns first block not false. if no object matches, calls ifnone , returns result when specified, or returns nil otherwise.

if no block given, enumerator returned instead.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -