I am wondering this syntax {:age.gt => 60}, which I find this syntax from mongoid. How does it work? I'm checking the source code of mongoid, it didn't extend the Symbol class much, and there is a matchers directory which contains gt.rb, lt.rb, .... These files are used for conditioning logic: greater than, less than .... I can't understand how it relates to Symbol class.
In plain irb session, it displays an error:
NoMethodError: undefined method `gt' for :age:Symbol
Anyone could explain me?
This is done by mongoid itself as part of Mongoid::Criterion::Complex in this symbol inflections file. Oddly this file is no longer there in the master branch, but I'm using 2.4.7 in my project and it exists there (it probably just moved but I can't find it in master).
Pretty interesting bit of magic. Magic I wouldn't consider all that necessary, :field => { :$gt => 5 } looks just fine to me, but anyway :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With