To call a static property on an instance of a class in Ruby, you would use the class name followed by the property name. Here is an example:
main.rb306 chars16 lines
In this example, @@my_static_property
is a static property defined on the MyClass
class. To access this property from an instance of the class, print_static_property
uses the class name self.class
and the syntax class_name.static_property_name
to access the value of my_static_property
. Output of the above program will be:
main.rb14 chars2 lines
gistlibby LogSnag