-1

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

结果.合并(
        简介:自我)

任何帮助将不胜感激

4

2 回答 2

5

Depends on the context. ie. where you found this line of code.

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

p = Profile.new
p.foo

In this case "self" will be referring to the object "p", which is the current object in the context where "self" is used.

于 2012-10-17T07:39:58.790 回答
3

它正在合并当前对象 - 配置文件到结果

http://jimmycuadra.com/posts/self-in-ruby

于 2012-10-17T07:33:53.813 回答