在 ruby​​ 中调用超类中的另一个方法 [英] calling another method in super class in ruby

查看:33
本文介绍了在 ruby​​ 中调用超类中的另一个方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<前>A级定义一个把 'in #a'结尾结尾B级<一种定义一个乙()结尾定义b#这里我想打电话给A#a.结尾结尾

解决方案

class B 一种别名 :super_a :a定义一个乙()结尾定义bsuper_a()结尾结尾

class A
  def a
    puts 'in #a'
  end
end

class B < A
  def a
    b()
  end
  def b
    # here i want to call A#a.
  end
end  

解决方案

class B < A

  alias :super_a :a

  def a
    b()
  end
  def b
    super_a()
  end
end  

这篇关于在 ruby​​ 中调用超类中的另一个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆