When I had a look into the ActiveRecord source today, I stumbled upon these lines
name = -name.to_s
and
ar.aggregate_reflections = ar.aggregate_reflections.merge(-name.to_s => reflection)
What purpose does the - operator serve for on the symbol name?
>Solution :
That’s String#-@:
Returns a frozen, possibly pre-existing copy of the string.
Example:
a = "foo"
b = "foo"
a.object_id #=> 6980
b.object_id #=> 7000
vs:
a = -"foo"
b = -"foo"
a.object_id #=> 6980
b.object_id #=> 6980