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
Post a Comment