user3636189
user3636189

Reputation: 193

Ruby. Explicit and implicit blocks

I am learning Ruby on RubyMonk. And I cannot perform this lesson:

We have a method called filter that accepts an explicitly passed block. We look to the block to tell us whether a value from the array should be accepted or rejected.

The Array#select method does exactly this but requires an implicit block. Try converting the explicit block into an implicit block and passing it on to Array#select.

def filter(array, block)
  return array.select # Your code here
end

What I should do?

Upvotes: 0

Views: 786

Answers (1)

Joel Brewer
Joel Brewer

Reputation: 1652

def filter(array, block)
  return array.select(&block)
end

Note that the answers for each problem are accessible from the page. Simply click the link titled "See the Solution"

Upvotes: 1

Related Questions