Why does Enumerable#detect need a Proc/lambda?

Viewed 1715

Enumerable#detect returns the first value of an array where the block evaluates to true. It has an optional argument that needs to respond to call and is invoked in this case, returning its value. So,

(1..10).detect(lambda{ "none" }){|i| i == 11} #=> "none"

Why do we need the lambda? Why don't we just pass the default value itself, since (in my tests) the lambda can't have any parameters anyway? Like this:

(1..10).detect("none"){|i| i == 11} #=> "none"
5 Answers
Related