class A def hello p 'hello' endenda1 = A.newa2 = A.newdef a2.hello super p "world"end a1.helloa2.hello
class A def hello p 'hello' end end a1 = A.new a2 = A.new def a2.hello super p "world" end a1.hello a2.hello
喵呜喵5 发表于 2015-3-16 22:42 涉及元编程相关,并没有必须搞懂的必要,直接记住然后使用就好了, 如果一定要弄明白的话,关键字: Ruby e ...
tan12345 发表于 2015-3-16 23:02 看了你的例子,我觉得和继承有点类似,继承了这个方法,但是重写了这个方法?? 可是你这个是实例的方法 ...
taroxd 发表于 2015-3-17 12:34 没有搞懂的必要。想搞懂的话,推荐的参考书籍:Metaprogramming Ruby 2 另外,这个类的官方叫法是 singl ...