看板 Ruby 關於我們 聯絡資訊
※ 引述《contagious (布穀飽吃不堡)》之銘言: [恕刪] : 另外, Ruby 根本不擔心型態的問題, : 只要物件能完成要求的動作就好了。 : 這就是所謂 Duck Typing。 關於 Duck Typing 的解說,可以看這篇 http://en.wikipedia.org/wiki/Duck_typing In computer science, duck typing is a term for dynamic typing typical of some programming languages, such as Smalltalk, where a variable's value itself determines what the variable can do. It also implies that an object is interchangeable with any other object that implements the same interface, regardless of whether the objects have a related inheritance hierarchy. Duck Typing 代表的意思是讓 variable 的 value 決定他的type,而非強制去定義他們。 這也代表每個 variable 可以跟其他的物件交換,因為他們都有一個共用的 Interface 而不是去定義首棟另外一個 interface 。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.230.115.163