I guess I could make a small module and require it, but then I need to
require it two times. I'm starting to think about memory even though for
this it would be very cheap anyway.
I guess I could make a small module and require it, but then I need to
require it two times. I'm starting to think about memory even though for
this it would be very cheap anyway.
Sounds like you're confusing "include" with "require". You could
"require" a file 50 times, but Ruby would loading it only once.
If you create a ruby module in would use "include" to include the module
into a class. But, it seems like a bit of overkill to create a module
that containing no methods, but only a single constant. I think I'd
simply put the constant on whatever class is dealing with your color
pallets.
Example:
class MyController
DARK_PALETTE = {
:background => "323232",
:header => "4d4c4d"
}
...
...
end
Then from anywhere else you need the constant:
MyController::DARK_PALETTE
The other, probably better, option would be to setup a custom
configuration YAML file that includes all your application specific
constants that gets loaded at startup. That way application wide
settings are separated from the application's code.
There was a Railscasts episode a good while back that showed an example
of setting up a YAML Configuration File: