What does @@variable mean in Ruby?
- by Andrew
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?