Reflection and discovery and more in Ruby & SonicPi ππ΅οΈββοΈ #5
Replies: 4 comments 1 reply
-
methods
|
Beta Was this translation helpful? Give feedback.
-
variables
Outer scope variables included in local-variables |
Beta Was this translation helpful? Give feedback.
-
CONSTANTSAny identifier starting with an uppercase letter. Class and module definitions (see Modules and Classes) also define constants, assigned to the class/module name:
See also: Constants scoping section in βModules and Classesβ chapter. |
Beta Was this translation helpful? Give feedback.
-
AssignmentIn the following sections any place βvariableβ is used an assignment method, instance, class or global will also work:
TBC! .... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Finding things like
__FILE__
__FILE__
is a special literal in Ruby that returns the name of the current source file as a string ΒΉ. It is used to reference the current file name in the code being executed. For example,require File.dirname(__FILE__) + "/../../config/environment"
is a common usage of__FILE__
ΒΉ.In Sonic Pi,
__FILE__
is also a special literal that returns the name of the current source file as a string Β². It can be used to reference the current file name in the code being executed, similar to its usage in Ruby.To identify what class/module
__FILE__
belongs to, you can use theclass
method on it. For example,__FILE__.class
will returnString
ΒΉΒ².To find things by name or source location and declaration, you can use Ruby's built-in reflection capabilities. For example, you can use
Module.constants
to get an array of all defined constants in the current scope ΒΉ. You can also useModule.nesting
to get an array of modules nested at the point of call ΒΉ. To find all methods that begin with "__" or are all uppercase, you can useModule.instance_methods(false).grep(/^__/)
andModule.instance_methods(false).grep(/^[A-Z_]+$/)
respectively ΒΉ.I hope this helps!
Source: Conversation with Bing, 27/09/2023
(1) What does FILE mean in Ruby? - Stack Overflow. https://stackoverflow.com/questions/[2](https://kevinjmurphy.com/posts/revisiting-calling-sonic-pi-from-ruby/)[2](https://kevinjmurphy.com/posts/revisiting-calling-sonic-pi-from-ruby/)4379/what-does-file-mean-in-ruby.
(2) Revisiting Calling Sonic Pi From Ruby - Kevin Murphy. https://kevinjmurphy.com/posts/revisiting-calling-sonic-pi-from-ruby/.
(3) sonic-pi/core.rb at dev Β· sonic-pi-net/sonic-pi Β· GitHub. https://github.com/sonic-pi-net/sonic-pi/blob/dev/app/server/ruby/core.rb.
Beta Was this translation helpful? Give feedback.
All reactions