Well this seems like it should be a simple thing but I can’t seem to find what I need. Currently I have two variables: frequency and period. frequency is set to a number (eg 1) and period is set to “month” or “year”. What I want to do is is use these variables to calculate x months from now.
I’ve seen the 1.month.from_now and 1.year.from_now but what I need is something like:
eval("#{frequency}.#{period.downcase}.from_now")
but I’m not sure about the use of eval as I’m new to Rails/Ruby and in PHP the use of eval usually means you’re doing something wrong.
Is eval evil in Rails?
eval is pretty slow. You can use Object#send:
And you can read about the speed here.