June 2007
Intermediate to advanced
294 pages
8h 6m
English
In this script, we’ll filter Arrays using an arbitrary number of Procs. As before, we’ll open up the Array class, this time adding two methods. Again, we’ll filter digits based on simple mathematical tests. Let’s take a look at the source code and see what’s different.
#!/usr/bin/env ruby
# matching_compound_members.rb
=begin rdoc
Extend the built-in <b>Array</b> class.
=end
class Array
=begin rdoc
Takes a block as an argument and returns a list of
members matching the criteria defined by that block.
=end
❶ def matching_members(&some_block) Block Arguments
find_all(&some_block)
end
=begin rdoc
Takes an <b>Array</b> of <b>Proc</b>s as an argument and returns all members ...Read now
Unlock full access