I know what
class << self
does. But what is the underlying mechanism of this trick?
<< in Ruby is Binary Left Shift Operator
So we are doing binary left shift on class variable ?
Please clarify.
It's not just binary left shift - << in Ruby is also the singleton class definition syntax. This syntax is used because all objects representing classes in Ruby are singleton classes.
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