ruby - Require a module file and interact with its module? -
I have a random module file in a folder.
e.g. "User.rb" includes "Module User", "CustomerRbb", which includes "Module Client" and so on.
I want to require all the files and want to print all module methods.
Here is my current code:
@@ data_module_methods = [] All files in the data folder # repeat [file. (Aprot, "data", "* .rb")]. Do each. File | File Required # Give me the module name from the file path (hence the ./data/user.rb will give me the user) data_module_name = file.split ("/"). [] {- (1) .split ("."). [] (0). #Delete: Print the names of all method, here it fails, because the data_module_define is a string and not the module :) data_module_name.instance_methods.each do | Method @@Data_Modules_mination & lt; & Lt; Method ending
How can I do this?
Thank you
To get you each module from its name, Kernel # const_get
method, therefore:
... kernel.const_get (data_module_name)) .instance_methods.each do it. Method ...
Comments
Post a Comment