In Ruby, I'd like to define a method that takes an argument, which returns a proc full of methods that make use of that argument. Something like the following
def test(word)
proc do
def hello
puts word
end
end
end
my_proc = test('hello')
my_proc.call.hello
When running this code, the local variable 'word' is undefined
To give some more context, I am trying to make use of association extensions, which allow you to provide a block of methods to an association to define extra helper methods on the association. I have some methods I'd like to use on several similar active record models with similar associations, but they only differ by a certain symbol when making calls (the name of the join table passed to through
on a has_many
relationship). So ideally I was thinking of making a method that accepts that symbol, which could then be used in the implementation of the association extension.