Is it possible with Ruby to instantiate a class and store the instance within the same class as constant?
class MyClass
DEFAULT = MyClass.new("haha")
def initialize(arg)
puts(arg)
end
end
# use it
instance1 = MyClass::DEFAULT
instance2 = MyClass.new("hohoho")
I tried this, but I get some strange results: 'initialize': wrong number of arguments (given 1, expected 0) (ArgumentError) at the line of the DEFAULT declaration.