time_constants icon indicating copy to clipboard operation
time_constants copied to clipboard

Use const_missing instead of defining every time constant manually.

Open postmodern opened this issue 13 years ago • 2 comments

You could use const_missing to dynamically return values for time constants, without having to manually define every single time constant. Additionally you could call const_set or memoize the values with a lazy Hash.

postmodern avatar Feb 22 '12 23:02 postmodern

The whole point is to avoid methods.

ryanking avatar Feb 22 '12 23:02 ryanking

If you use const_set with const_missing, const_missing will only be called once per time constant.

postmodern avatar Feb 22 '12 23:02 postmodern