What are these variables?
Class User
TOTO = 1
TITI = 2
end
User::TOTO # 1
User::TITI # 2
any links to the doc? Thanks,
What are these variables?
Class User
TOTO = 1
TITI = 2
end
User::TOTO # 1
User::TITI # 2
any links to the doc? Thanks,
TOTO
and TITI
are defined as constants with values 1 and 2 respectively within the User class.
You can access these constants from within the the user class itself by just referring them as TOTO
and TITI
But if you want to access these constants from outside the user class then you have to use the class name as well which is what you are doing I guess, i.e. User::TOTO
and User:TITI
Here is little tutorial on the constants.
Class
should be lowercase, for one.
class User
TOTO = 1
TITI = 2
end
User::TOTO # 1
User::TITI # 2
User
, TOTO
and TITI
are all constants, with User
referencing a class, and TOTO
and TITI
both being stored inside that class's namespace and both referencing integers.
In ruby, you have several types of variable, all identified by theit starting character.
@
sign, and are accessible whenever self
evaluates to the instance that eh instance variable was defined in (normally within instance methods)@@
sign, and are acessible whenever inside the class that first defined them, or any of its subclasses, or any of their instances.