16.7 What I do not understand on types of variables and their relation with a class?


#1

I got Hello by two ways:
1.

class MyClass
    $my_variable = "Hello!"
end
puts $my_variable

2.

And the second one that shows that decared as a local variable with $ can work not from inside a class as it was explained in lesson, and this is not just a local variable so on if it works on it:

$my_variable = "Hello!"
class MyClass
puts $my_variable
end

But why declared before the class MyClass a global variable named my_variable doesn't work on it? Should not it be available anywhere? What I do not understand? I fill like the explanation of the lesson is not really clear.

my_variable = "Hello!"
class MyClass
puts my_variable
end

#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.