在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#单例方法:对象的实例方法,其只属于具体类实例对象
#实例方法,属于类的每个实例对象。单例方法只出现在单个实例对象中
class Person def talk puts "This is a Person class." end end p1=Person.new p2=Person.new #定义单例方法,首先要生成一个实例对象,其次,要在方法名前加上对象名和一个点号“.” def p2.talk puts "This talk method belongs to p2." end def p2.laugh puts "laugh method belongs to p2." end p1.talk #This is a Person class. p2.talk #This talk method belongs to p2. p2.laugh #laugh method belongs to p2. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论