------ art_169764_631820.1152641882498
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Good example. Also because it's rails centric (something I'd eventually
like to get to)
I am running into some select errors though , via the select statement. If
your up to reading it through (I don't find any typos matched against your
code), if not that is fine as the explanation helped me.
class ClientDB
Record truct.new(:client_name, :location, :projects)
def initialize
@records Record.new("Gray Productions", "Oklahoma",
["Ruby Quiz", "Rails Extensions"] ),
Record.new( "Serenity Crew", "Deep Space",
["Ship Enhancements"] ),
Record.new( "Neo", "Hollywood",
["Rails interface for the Matrix"] ) ]
end # end of method
def select( query )
# parse query String
rules ash[*query.split(/\s*AND\s*/).map do |rule|
rule.split(/\s* */).map { |value| value.sub(/^['"](.+)['"]$/,
'\1') }
end.flatten ]
#match records
@records.select { |record| block_given? and yield record }
rules.all? { |field, value| record.send(field) value }
end # end of method
end # end of class
require "pp"
db lientDB.new
pp db.select { |record| record.client_name ! Gray Productions" }
pp db.select { |record| record.client_name +~ /crew/i }
pp db.select { |record| record.projects.size 1 }
pp db.select { |record| record.projects.include? "Ruby Quiz" }
--------
On 7/11/06, James Edward Gray II <james / grayproductions.net> wrote:
>
> On Jul 11, 2006, at 11:55 AM, Dark Ambient wrote:
>
> > Just curious, I'm just learning about Procs, and have already
> > looked at
> > using blocks.
> > Are they very close in the way they function. It seems that way to
> > me.
> > Perhaps I'm wrong.
> > Is one favoured above the other ?
>
> I see David has already answered your question here, but just in case
> it helps I wrote about this on my blog a while back:
>
> http://blog.grayproductions.net/articles/2006/01/05/code-as-a-data-type
>
> James Edward Gray II
>
>
------ art_169764_631820.1152641882498--