maudulus
maudulus

Reputation: 11035

What does the @ sign do?

I have code @array = array. What does putting the @ sign before array do?

Upvotes: 0

Views: 127

Answers (1)

Shoe
Shoe

Reputation: 76240

Variables in the form @<something> are instance variables in Ruby. They are part of the class in which you create them.

For example in:

class Something
    def initialize(x)
        @x = x
    end
end

@x is an instance variable of the class Something while x is a simple local variable of the method initialize.

Upvotes: 3

Related Questions