In Ruby, static properties do not exist as they do in some other languages. However, you can achieve the same result using class variables:
main.rb168 chars12 lines
This code defines a class MyClass
and a class variable @@my_property
that can be accessed by calling MyClass.my_property
. The self.
before the method name makes it a class method, and the =
after the method name allows us to assign a new value to the property using the =
operator.
Here's an example of how you would use it:
main.rb144 chars4 lines
gistlibby LogSnag