문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top