如何修改Ruby类?
根据上的建议,我需要在Ruby 1.9.2中的DateTime中添加一个getlocal方法。我该怎么做?感谢阅读您可以像打开任何其他类定义一样打开一个类定义来添加数据如何修改Ruby类?,ruby,Ruby,根据上的建议,我需要在Ruby 1.9.2中的DateTime中添加一个getlocal方法。我该怎么做?感谢阅读您可以像打开任何其他类定义一样打开一个类定义来添加数据 class DateTime def getlocal self.to_time.getlocal.to_datetime end end 只需将其放入文件中,即可将该方法修补到DateTime类中。 打开已存在的类时,可以向其添加代码或重写现有方法。只需像打开任何其他类定义一样打开一个类定义即可添加数据 cl
class DateTime
def getlocal
self.to_time.getlocal.to_datetime
end
end
只需将其放入文件中,即可将该方法修补到DateTime
类中。打开已存在的类时,可以向其添加代码或重写现有方法。只需像打开任何其他类定义一样打开一个类定义即可添加数据
class DateTime
def getlocal
self.to_time.getlocal.to_datetime
end
end
只需将其放入文件中,即可将该方法修补到DateTime
类中。打开已存在的类时,可以向其添加代码或重写现有方法