I need some help with defining a dynamic method.
Basically, I have many classes that reside within one module. I need to generate a list of methods within each class based on a passed in list of strings, which is specific to each class (i.e. different classes have different list of strings). The body of the method should be something like:
client.call(the_string, @an_instance_variable)
So basically I want to create a method that I can use in each of these classes that reside within the same module, in order to dynamically generate a bunch of methods based on the array of strings that was passed.
Something like:
register_methods @@string_array
So say “name” was a string in the array, then it would generate a method as such:
def name
client.call("name", @an_instance_variable)
end
I hope that makes sense. I’m stumped after trying all sorts of things for hours, and would really appreciate any input. Thanks!
don’t have an irb available, but this should work