自我代表什么?红宝石

Jac*_*han -1 ruby

刚刚在RoR 3.2.8中遇到以下代码.这是否意味着self属于合并函数或类?

results.merge(
        profile: self)

任何帮助将不胜感激

小智 5

取决于上下文.即.你找到这行代码的地方.

class Profile
  def foo
    results.merge(profile: self)
  end
end

p = Profile.new
p.foo
Run Code Online (Sandbox Code Playgroud)

在这种情况下,"self"将指向对象"p",该对象是使用"self"的上下文中的当前对象.