Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby class << self

Tags:

class

ruby

self

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.

like image 1000
Sergii Shevchyk Avatar asked Dec 28 '25 16:12

Sergii Shevchyk


1 Answers

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.

like image 93
Nate Avatar answered Dec 31 '25 19:12

Nate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!