New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to create singleton in crystal #444
Comments
solved by: class Aa
property bla, some
end
A = Aa.new
A.bla = 10 |
You can also do: class A
def self.bla
@@bla
end
def self.bla=(@@bla)
end
end
A.bla = 10 |
is there macro for this? class A
self.property bla
end |
Not yet. It would actually be nice to have the |
IMO it's not wise to allow |
Other general elegant singleton solution in Crystal can be, class Config
property params = {} of Symbol => (String | Bool | Float64)
def initialize
@params[:logs] = false
@params[:simulate] = false
end
def self.params
self.instance.params
end
def self.instance
@@instance ||= new
end
end While accessible and "dynamic" by any other classes as Config.params[:value] = 7000.85 |
in ruby:
how to to the same in crystal
The text was updated successfully, but these errors were encountered: