On Apr 9, 10:49 am, Shawn <[email protected]> wrote: > Sometimes when building a hash of conditions on which to filter a > dataset, I end up with an empty hash: > > attrs = {} > attrs[:year] = year if year > attrs[:state] = state if state > > # attrs == {} if !year and !state
I should point out the Sequel way to do this: ds = ds.filter(:year=>year) if year ds = ds.filter(:state=>state) if state Building up a hash of attributes is an ActiveRecord way to approach the problem, but that approach is not usually needed in Sequel. That's not to say that I won't support the patch I attached earlier (I will if it doesn't harm performance too much), but I don't recommend the approach the patch would allow when the above works. About the only time I'd recommend your approach is if the hash is being built in a method that has no access to the dataset it will be used on, and even then I'd consider it a code smell. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
