As I'm browsing through a Rails source code, it contains the line:
@@autoloads = {}
What does @@
mean in Ruby?
It means to access a class property (a property namespaced to the class), not an instance one (a property that exists for each instantiated object from that class).
In your example, the @@autoloads
will persist for the length of your program.
class TestObj
@@prop = 0
def get_prop
@@prop
end
def increment_prop
@@prop += 1
end
end
a = TestObj.new
b = TestObj.new
a.increment_prop
puts b.get_prop # 1
CodePad
@@ identifies a class variable.
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