一、实例方法和类方法
class Person
def my_instance_method 实例方法
puts "I'm an instance method"
end
def self.my_class_method 类方法
puts "I'm a class method"
end
end
二、定义类方法多种方法

备注:第一种用类Person代替了self,第二中用class << self ,end来包含多个类方法
三、例子

类方法:

实例方法:

一、实例方法和类方法
class Person
def my_instance_method 实例方法
puts "I'm an instance method"
end
def self.my_class_method 类方法
puts "I'm a class method"
end
end
二、定义类方法多种方法
备注:第一种用类Person代替了self,第二中用class << self ,end来包含多个类方法
三、例子
类方法:
实例方法:
本文标题:四、实例方法和类方法
本文链接:https://www.haomeiwen.com/subject/rzusuxtx.html
网友评论