On Feb 28, 10:08 pm, David Lee <[email protected]> wrote:
> How about splitting where and filter to do different things?
>
> Both these would be the same:
>
>  dataset.filter {|o| o.a > 1}
>  dataset.where {a > 1}

Nope.  They are aliases now and I don't think it is a good idea to
change that.  What would be the justification for changing it?  I
understand not breaking compatibility for filter, but why would you
want to break compatibility for where instead?

> You can also refer to local variables in #where by passing them as
> arguments:
>
>  price = 1
>  name = "hotdog"
>  # The following two statements result in the SQL: "price > 1 AND name
> = 'hotdog'"
>  dataset.filter {|o| (o.price > price) & (o.name == name)}
>  dataset.where(price, name) {|p,n| (price > p) & (name > n)}

In your example, if I'm understanding it correctly, price and p in the
block will be equal (same with name and n).  With an instance_eval'd
closure, you still have access to local variables in the lexical
scope.  You can force the VirtualRow instance method to be called
instead of the local variable by:

  dataset.where{(price() > price) & (name() > name)}

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to