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
Post a Comment