Im trying to dynamically require and then include modules inside a initialize method.
# file: object.rb
class Object
attr_accessor :array
def initialize array
@array = array
@array.each do |f|
require_relative "#{f}"
include f.capitalize # the method name is the same as the filename
puts @variable # property from included method
end
end
end
object = Object.new ['a','b','c']
with these module files
# file: a.rb
module A
@variable = 'string A'
end
and so on for b and c
i keep getting an error :
`block in initialize': undefined method `include'
What am i doing wrong here and is there a better way to achieve what i'm trying to do?