I have the following class:
class Foo
include BaseFoo
attr_reader :with_context
def initialize(with_context: %i[bar baz])
@with_context = with_context
end
def call
puts bar # Should return 'lorem ipsum'
puts baz # Should return 'lorem ipsum'
end
end
How can I dynamically define methods in module BaseFoo based on the values of with_context?
Unfortunately, this wont workk because the module doesnt know what with_context is.
But to give you a general sense of what needs to be achieved. Pseudo code:
module BaseFoo
with_context.each |context|
define_method context do
'lorem ipsum'
end
end
end
Basically, BaseFoo should have the following public methods:
def bar
'lorem ipsum'
end
def baz
'lorem ipsum'
end