0

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

  1. Can any module be a class? (I just tried puts BaseObject.class and that fails as it's an uninitialized constant)

  2. 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!

3
  • I don't know Sonic Pi, but if it's based on Ruby, the Ruby docs on Modules and Classes might help. It explains what modules and classes are for and how to use them. Using ObjectSpace to traverse the known objects in order to learn about them however seems very tedious. You should better refer to the official docs / reference. Commented Sep 17, 2023 at 15:42
  • @Stefan Sonic PI aims to be a kind of Ruby like subset language but seems to use a standard Ruby interpreter. However it comes with a warning that "Using custom classes is not possible using the officially supported Sonic Pi syntax. Such a thing is potentially doable using vanilla Ruby syntax, which Sonic Pi’s API is built on, but there is no guarantee that if it works, it would continue to work in future versions." . Commented Sep 17, 2023 at 17:11
  • Thanks guys, duly noted. I saw something that demonstrated overriding, where custom classes are desired, or even necessary. For now I was just curious to see if classes (and other things) are 'aware' of the modules they belong to... will keep tinkering (and reviewing) Commented Sep 17, 2023 at 20:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.