seg*_*egy 17
最简洁的答案是不.
这就是推理,Java/C#接口定义了实现类至少提供的方法签名.
另外:
例:
module SimpleConversation
class NamespacedExample
def poke
puts "ouch"
end
end
attr_accessor :partner_name
def converse
partner_name ||= "Slowpoke"
speak + "\n#{partner_name}: Yes they are"
end
def self.yay
puts "yay"
end
end
class Foo
include SimpleConversation
attr_accessor :name
def speak
name ||= "Speedy"
"#{name}: tacos are yummy"
end
end
x = Foo.new
x.name = "Joe"
x.partner_name = "Max"
puts x.speak
puts x.converse
y = SimpleConversation::NamespacedExample.new
y.poke
SimpleConversation.yay
Run Code Online (Sandbox Code Playgroud)
我认为我将模块等同于类似于C#中的扩展方法.您正在向其他地方实际定义的现有类添加功能.在C#或Java中没有一个确切的模拟,但我绝对不会将它视为一个接口,因为实现是派生的以及接口.
| 归档时间: |
|
| 查看次数: |
7940 次 |
| 最近记录: |