我见过最清楚的解释class_eval 和 instance_eval
by
at 2013-04-02 07:06:59
original http://hlee.iteye.com/blog/1840489
忘了,看一次就能回忆起来
class A
# defs here go to A
puts self # => A
class << self
#defs here go to A's eigenclass
end
end
A.class_eval do
#defs here go to A
end
A.instance_eval do
#defs here go to A's eigenclass
end
s = "Hello World"
class << s
#defs here go to s's eigenclass
end
<br><br>
<span style="color:red">
<a href="http://hlee.iteye.com/blog/1840489#comments" style="color:red">已有 <strong>0</strong> 人发表留言,猛击->><strong>这里</strong><<-参与讨论</a>
</span>
<br><br><br>
ITeye推荐