4 ms·
"In Ruby, ordinary variables lack sigils, but "$" is prefixed to global variables, "@" is prefixed to instance variables, and "@@" is prefixed to class variable
by rcfox 15y ago
"In Ruby, ordinary variables lack sigils, but "$" is prefixed to global variables, "@" is prefixed to instance variables, and "@@" is prefixed to class variables."[0]
Okay, I don't know Ruby well enough to know if these are commonly used features, but the statement that there are no sigils is false.
[0] http://en.wikipedia.org/wiki/Sigil_(computer_programming)#Language_comparison http://en.wikipedia.org/wiki/Sigil_(computer_programming)#La...
- pyrhho 15y ago@ is common.. The others are pretty rare.
- prophetjohn 15y agoRuby even uses some predefined globals (eg $_) that are pretty much straight out of Perl. http://www.tutorialspoint.com/ruby/ruby_predefined_variables.htm http://www.tutorialspoint.com/ruby/ruby_predefined_variables...
- jamesbritt 15y agoRuby even uses some predefined globals (eg $_) that are pretty much straight out of Perl. They exist, and while I'm a fan of $: over $LOAD_PATH I don't think I've even seen $_ used in the wild.
- prophetjohn 15y agoI don't really have the perspective to comment on how common they are, but they do exist. Ruby is full of little things like this, which one of the things I simultaneously love and hate about Ruby
- DanielRibeiro 15y agoYou are right. What I should have said is: "the lack of sigils to indicate type of a variable". In perl this noise is everywhere, while in Ruby its is a lot less common. Specially if you use accessor methods. In ruby, unlike smalltalk, this instance variable sigils are pretty much impossible to get rid off. This is because in Smalltalk local variables have to be declared, and if you don't, the Language will try to use the instance variables. In Ruby it would default to being a local variable, if already assigned, or invoking a method with no arguments.