What does @@variable mean in Ruby?
Posted
by
Andrew
on Stack Overflow
See other posts from Stack Overflow
or by Andrew
Published on 2011-05-04T21:33:13Z
Indexed on
2012/09/01
3:38 UTC
Read the original article
Hit count: 116
What are Ruby variables preceded with double at signs (@@
)? My understanding of a variable preceded with an at sign is that it is an instance variable, like this in PHP:
PHP version
class Person {
public $name;
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
Ruby equivalent
class Person
def set_name(name)
@name = name
end
def get_name()
@name
end
end
What does the double at sign @@
mean, and how does it differ from a single at sign?
© Stack Overflow or respective owner