david karapetyan
7/3/2007 2:50:00 AM
On Jul 2, 3:20 pm, Reacher <brandon.g.jo...@gmail.com> wrote:
> Can you define function names dynamically in Ruby? Say you have:
>
> class Myclass
> def initialize()
> @name = "STR"
> end
>
> def STR1
> ...
> end
>
> def STR2
> ...
> end
>
> ...
>
> end
>
> can the STR* functions be generated on the fly, based on the value of
> @name?
I think you should look up singleton classes and the method
"module_eval". I am not an expert on these issues but every time
dynamic programming comes up in ruby those two concepts pop up as well.