I completely understand, and will be perfectly happy with using =~/!~ for equality. It's so cool how you just took an unused operator and imbued it with a power to do so many things, with so little code.
On Tue, Mar 24, 2015 at 1:19 AM Jeremy Evans <[email protected]> wrote: > On Monday, March 23, 2015 at 5:01:02 PM UTC-7, Janko Marohnić wrote: >> >> Hi Jeremy, >> >> Thank you for going ahead and implementing `=~` and `!~` for virtual >> rows, I really appreciate. I noticed that you also gave it other >> functionality, like equality/inequality. This got me thinking, because >> Squeel in its DSL simply uses `==` and `!=` for equality, which I find >> really natural. >> >> DB[:movies].where{year == Date.today.year}.sql >> # => SELECT * FROM movies WHERE (year = 2015) >> >> Is it possible to add the `==` and `!=` operators to Sequel's virtual >> rows as well? I'm willing to make a pull request if you would like. >> > > It's possible, but it is a bad idea and would break a lot of code. ==/!= > is currently used to test for equality, not for creating new expressions: > > Sequel.expr(:year) == Sequel.expr(:year) # true > Sequel.expr(:year) == Sequel.expr(:month) # false > > Among other things, this behavior is relied upon when using expressions as > hash keys. > > Personally, I strongly disagree with overriding ==/!= to return > non-boolean, it breaks POLS: > > if some_expression_object == 1 > # always true if == returns an expression > end > > Thanks, > Jeremy > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sequel-talk" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sequel-talk/tPKPfAhMzGY/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sequel-talk. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
