Em 10-12-2012 19:40, Ernie Miller escreveu:
On Monday, December 10, 2012 4:08:06 PM UTC-5, Rodrigo Rosenfeld Rosas
wrote:
What if a column is named "class"? I'd rather prefer something
like that:
Post.where { |post|
post[:title].like('zomg%') | post[:class].like('bbq%')
}
In Squeel's specific case, the DSL object is a blankslate, so it works
fine. Hash-style syntax would be another option. That would avoid
method_missing overhead for simple column access, which would be a
good thing, but make things less readable, as well. Not my
personally-preferred tradeoff, but certainly could see a case for it.
There is a recent (scattered) discussion about this topic on ruby-core
mailing list:
https://bugs.ruby-lang.org/issues/4085#note-249
As noticed in that scattered thread, the odd-named columns (such as
"dotted.column") aren't my only concern with Squeel approach (when the
block has zero arity) as there may be conflicts with local methods and
variables/arguments names.
And I don't see much difference (as you state it is less readable) between:
post[:title].like('zomg%')
and
post.title.like('zomg%')
But I find this more consisent:
post[:"dotted.column"].like('zomg%')
than this:
post.__send__(:"dotted.column").like('zomg%')
You could actually support both syntaxes, but if you do so you wouldn't
be able to support things like this in the future:
post.like(:some_column, 'some value')
as an alternative to
post[:some_column].like('some value')
Not that I think that would be wanted at some point but maybe we could
find some useful methods to define on the dsl object in the future.
With regards to GitHub stars, I wouldn't count much on that. I use GH
stars as a global "favorites" thing so that I can quickly find some
project I want to cite or take a closer look in the future. Most GH
projects I starred I don't actually use.
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Core" 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/rubyonrails-core?hl=en.