Reputation: 110725
I would like to do something like this from a Ruby script, within a loop:
I expect there are many better ways of doing this. For example, instead of step #2-#5 could I simply load 'a.rb' (within the loop) and invoke one one of its methods? Is there a better way by using eval() or something else? (Gaining an understanding of metaprogramming is on my Ruby to-do list.)
Upvotes: 1
Views: 396
Reputation: 98509
I think eval
is probably the right solution for dynamically-generated code; that's what it's designed for. Instead of creating a.rb
at all, just eval('some-code-that-would-be-in-a.rb')
.
Upvotes: 3