Naming Your Variables`


#1

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_
_end_

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.


#2

I tried this and it worked:

class MyClass
$my_variables = "Hello!"
end

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.


#3

I ve tried this : it works as well:

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