ruby - how to access variables in the "default" scope -


how access var in "default" scope in other class definition , this?

var = 1  class myclass def self.show var end  myclass.show #=> 1 

and btw notice self in "default" scope return main, what's this?

it's not possible. variables defined var = ... local variables.

defining global variable done $var = ....

another more hacky approach defining instance variable (@var = ...), require somehow main instance myclass.show doesn't seem worth work.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -