I've a module Settings
like the following:
module Settings
extend self
@_settings = {user: "user1"} #@_seetings would normally be filled with different (dynamic) options
attr_reader :_settings
def method_missing(name, *args, &block)
@_settings.has_key?(name.to_sym) ? @_settings[name.to_sym] :
raise(NoMethodError, "unknown configuration root #{name}", caller)
end
end
In my application I can use Settings.user
to access the option user
Now I would like to do something like this Settings.user = "some_user"
I've tried to add this:
def method_missing=(name, *args, &block)
#some code to assign the value
end
Unfortunately this is not working. (unknown configuration root user= (NoMethodError)
). What is the 'right' way to do this?