Rutger
Rutger

Reputation: 185

Use variable method names in rails

I'd like to DRY up my methods. I have several (legacy) methods with the same name except for a variable at the end. These methodes all do the same thing. These method names are used in publicly distributed URL's so renaming them is not an option. I'm looking for a way to use a flexibel method name or catch all method based on the begin of the method name. I read articles about calling method names with variables in them but that is not what I'm looking for here (I think). I'd like to do something like

def holiday_"#{var}"
 code
end

Any suggestions?

Regards,

Rutger

Upvotes: 0

Views: 336

Answers (1)

Thilo
Thilo

Reputation: 17735

I think what you're looking for is method_missing - take a look for example at these articles.

Upvotes: 1

Related Questions