> It's not backwards compatible. Among other things using instance_eval
> always changes the meaning of instance variables inside the block.
> Also, filter already accepts arguments along with the block and ANDs
> them together. It's actually less backwards compatible than my
> method, because to implement your method, you require that self be
> passed in, which isn't done now.
Sorry, I meant backwards-compatible on top of your proposed
implementation. Of course, if your proposal included the ability to
pass in arguments to filter, it would not be backwards-compatible even
with your solution.
>
> The thing I like about my solution is that if gives the user choice
> while being simple to understand. If you only need access to local
> variables (or don't need access to anything), don't have a block
> argument and use the less verbose method of creating identifiers and
> functions. If you need access to something other than local
> variables, give the block an argument and use the block's argument to
> create identifiers and functions, while having methods called without
> an explicit receiver go to the self object of the enclosing scope.
>
> Jeremy
I do like your solution in that it gives users the flexibility to
specify the WHERE clause in two different ways, but I think it might
be better having separate methods. The reason I proposed separating
filter and where was because #filter sounds like a Ruby term, whereas
#where sounds like SQL. I thought it would be nice to support the Ruby-
ish way of filtering through #filter while supporting the SQL-ish DSL
through #where.
# Looks like Ruby:
dataset.filter {|x| x.price > 1}
# Looks like Sequel:
dataset.where {price > 1}
This way, it is also easier to explain to users that #where does an
instance_eval on VirtualRow, whereas filter simply does a yield--
without condition on the arity of the block. You can say, "use #filter
to filter the dataset like an array; use #where for a SQL-like DSL."
By the way, have you thought of extending the DSL to be able specify
table.column without using the double underscores?
dataset.where {(users.id == posts.user_id) & (users.name < "M")}
# => "users.id = posts.user_id AND users.name < 'M'"
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---