Sometimes it seems handy to have an object with some configuration data, accessible globally. Since Crystal doesn’t have global variables anymore, my attempt was to utilize the
forward_missing_to macro like this:
struct Conf property foo : String? property bar : String? # ...many more properties... property zzz : String? end module Config extend self @@config = Conf.new forward_missing_to @@config end Config.foo = "foo"
But it doesn’t work:
undefined method 'foo=' for Config:Module
So, the only option I see at the moment, is to use a constant:
CONFIG = Conf.new CONFIG.foo = "foo" p CONFIG.foo #=> "foo"
But using a constant feels semantically wrong. Is there a more elegant way?