from understand, in ruby class variables preceded @@
while instance variables preceded @
. mean if they're defined inside class body without being preceded anything?
class myclass some_var = 'hello' end
what some_var
refer in case?
it local variable. see official documentation "local variables".
local variables, when declared within scope of class, evaluated whenever class loaded. try run this:
class myclass bad_idea = 1/0 def initialize puts "this silly #{bad_idea}" end end puts "i told wouldn't work!"
you'll zerodivisionerror: divided 0
, "i told wouldn't work!"
never printed.
Comments
Post a Comment