The following all define class methods within class Demo.
ruby 代码
- class Demo
- def Demo.meth1
- # ...
- end
- def self.meth2
- # ...
- end
- class <<self
- def meth3
- # ...
- end
- end
- end
本文介绍在Ruby中定义类方法的不同方式,包括使用类方法语法、类对象上的实例方法定义等。通过具体的代码示例展示了三种定义类方法的方法。
24

被折叠的 条评论
为什么被折叠?



