elephant

赫本之后 再无女神

Super_method

1
2
3
4
5
6
7
8
9
10
11
class A
  def show
    "a method"
  end
end

class B<A
  def show
    "b method"
  end
end

怎样用类B的对象调用A的show方法?

1
B.new.method(:show).super_memthod.call  #ruby 2.2可用

2.2之前

1
2
3
4
5
6
7
8
9
10
11
12
13
class A
  def show
    "a method"
  end
end

class B<A
  alias_method :super_show ,:show
  def show
    "b method"
  end
end
B.new.super_show