Naming Your Variables`


You can do one of two things:

1- Move my_variable out of the class and into the global scope, or

_class MyClass_
_ _
_ my_variable = "Hello!"_

_puts my_variable_

2- I can't get the second one!

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

puts my_variable                                      puts $ my_variable

They both give error so please help on the second one.


I tried this and it worked:

class MyClass
$my_variables = "Hello!"

puts $my_variable

Basically, it's what you have in option 2 on the right but without a space between the dollar sign and my_variable.


I ve tried this : it works as well:

class MyClass
my_variable = "Hello!"
puts my_variable