is that main.sound = ("bang") method?
Not. main.sound="bang" should set the instance variable or element of this variable.
With a dot ( main.sound ), you tell the object some method (in this case, sound ).
To manage local ruby ββvariables, create a new scope.
class E a = 42 def give_a puts a end def self.give_a puts a end binding end bin_e = _ # on pry E.give_a # error E.new.give_a # error
Both methods are not aware of a . After creating the class, a will disappear soon; it is deleted by the garbage collector. However, you can get this value using the binding method. It saves the local area in any place, and you can assign it to a variable.
bin.eval "a"
lambda have the area in which they were defined:
local_var_a = 42 lamb = ->{puts local_var_a} lamb.call()
Darek nΔdza
source share