D
Devin Mullins
Jamey said:def select(&select_cond)
result = []
@db.engine.get_recs(self).each do |rec|
result << rec if select_cond.call(rec) end
return result
end
Why not:
def select
result = []
@db.engine.get_recs(self).each { |rec| result << rec if yield rec }
result
end
Or if get_recs returns an Enumerable:
def select(&select_cond)
@db.engine.get_recs(self).select(&select_cond)
end
Or if not:
def select(&select_cond) #this is probably not very performant
@db.engine.get_recs(self).extend(Enumerable).select(&select_cond)
end
Sorry, can't help it, it's like a tic. YMMV.
That is awesome, and my hat is off to you.Kirk said:I *heart* that sort of query syntax. You'll see much the same thing in the
Kansas ORM:
results = ksdbh.selectPlanes) {|r| (r.country == 'USA') & (r.speed > 350)}
In this case, method_missing magic is mixed into that in such a way that the
Ruby code becomes a SQL statement for querying a relational database.
Devin