访问同一类中另一个实例变量中的实例方法变量

时间:2016-06-11 17:26:26

标签: ruby ruby-on-rails-4

我是rails的新手,我遇到了访问同一类但不同实例变量的变量的问题

class A

  def x
    @z = params[:something]
    #someother code i dont 
  end

  def y
    #self.x returns the full instance method but i just want @z without the entire method
  end
end

我该怎么做

1 个答案:

答案 0 :(得分:1)

假设在方法onResume之前调用了方法x,您可以使用y来获取实例变量