作者ireullin (raison detre)
看板Ruby
标题[问题] 关於Ruby的多型
时间Tue Apr 12 11:45:33 2011
小弟最近刚开始接触Ruby
所以有些语法还不太熟
下面这样写执行时会发生错误
请问Ruby没有提供多型的功能嘛
还是只有建构式如此呢
class HtmlElement
def initialize(szTag)
@arrEle = Array.new
@hAtr = Hash.new
@szTag = szTag
end
def initialize(szTag, szValue)
@arrEle= Array.new
@hAtr = Hash.new
@szTag = szTag
@arrEle.push(szValue)
end
end
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.220.71.34
1F:→ poga:这不是多型,这是function overloading,Ruby本身没有 04/12 12:01
2F:→ poga:但是可以用其他方式做到类似的效果 04/12 12:01
3F:→ ireullin:请问有参考的资料嘛,或搜寻什麽关键字 04/12 13:11