相关疑难解决方法(0)

是否有可能比较Ruby中的私有属性?

我在考虑:

class X
    def new()
        @a = 1
    end
    def m( other ) 
         @a == other.@a
    end
end

x = X.new()
y = X.new()
x.m( y ) 
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

错误消息是:

syntax error, unexpected tIVAR
Run Code Online (Sandbox Code Playgroud)

我如何比较来自同一类的两个私有属性呢?

ruby attributes private instance-variables

3
推荐指数
2
解决办法
2807
查看次数

标签 统计

attributes ×1

instance-variables ×1

private ×1

ruby ×1