I'm learning how to use SonicPi (an app that's built on Ruby, but isn't Ruby), and Ruby.
I actually have quite a few questions, so may need to start a few threads...
To begin with most recent conundrums...
I've been using puts to discover what's known , and the ObjectSpace to try to discover information on objects and collections (classes,modules,arrays,symbols...)
Using this method, along with the code and google, I see modules are used to manage resources (a bit like namespaces I guess)
When I add .class to any module, I seem to get the class of the module
Can any module be a class? (I just tried
puts BaseObject.classand that fails as it's an uninitialized constant)Also is it possible to inspect the modules using reflection, to see things like
- all modules
- classes in each module
- sub-classes in each module
I saw something which may be related, but haven't managed to use to get classes + more for each SubModule
One thing I do to prune the list of inherited methods from the Object base class:
my_object.methods - Object.instance_methods
I've been looking through ruby-docs (and several amazing blogs on all things ruby) but for allmodules the only thing I've found is the method in RDoc::Store, and I'm not sure if it's possible to gem install that to access that - if it helps (re what Ruby stuff is in SonicPi) puts Gem.class returns the Module, whilst puts RDoc stuff fails as that's not known... on closer inspection I see RDoc.rb is not in my core/lib RunTime folder, AND there are zero RDoc objects in the source code! Suggesting rdoc.bat and everything at built during app-install...
TlDR; How to see stuff in each module/member Thanks!
ObjectSpaceto traverse the known objects in order to learn about them however seems very tedious. You should better refer to the official docs / reference.