From: Colin Bartlett Date: 2010-09-18T10:56:07+09:00 Subject: Re: Get hours, seconds and time from Date.day_fraction_to_time --00163628391a1be7c404907efbbc Content-Type: text/plain; charset=ISO-8859-1 See below at *** for two "work-arounds" which seem to allow you to do what you want in Ruby 1.9 as well as in 1.8.6 and 1.8.7. Some links for explanations of private and public (and protected) methods: http://weblog.jamisbuck.org/2007/2/23/method-visibility-in-ruby Here (for example) under Access Control: http://ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html ... Private methods cannot be called with an explicit receiver. Because you cannot specify an object when using them, private methods can be called only in the defining class and by direct descendents within that same object. Compare the "full" code for the 1.8 and 1.9 versions of Date. (See just below.) The 1.8 version can only be used as a class method Date.day_fraction_to_time, but the 1.9 version can also be used as a *private* instance method. That said, I don't know why the class (singleton) method day_fraction_to_time was changed from public in Date before 1.9 to private in 1.9, and I would welcome any enlightened suggestions. (One reason for making a method private is, I assume, to warn people that an internal implementation detail might change, so it would be unwise to use such a private method in case its implementation changes in the future. That gives more freedom to the code originator for future changes.) # In 1.8: class Date #... def self.day_fraction_to_time(fr) #... end #... end # But in 1.9: class Date #... t = Module.new do private #... def day_fraction_to_time(fr) # :nodoc: #... end #... end extend t include t #... end *** work arounds require "date" start = DateTime.now sleep 3 stop = DateTime.now # minutes puts( ((stop - start) * 24 * 60).to_i ) puts "Date.day_fraction_to_time" begin hours, minutes, seconds, frac = Date.day_fraction_to_time( stop - start ) # works in 1.8.6 & 1.8.7 p hours, minutes, seconds, frac rescue # raises exception in 1.9.1 p $! end puts "Date.day_fraction_to_time using __send__" hours, minutes, seconds, frac = Date.__send__( :day_fraction_to_time, stop - start ) p hours, minutes, seconds, frac puts "Date.day_fraction_to_time using wrapper" class Date class << self def wrap_day_fraction_to_time( day_frac ) day_fraction_to_time( day_frac ) end end end hours, minutes, seconds, frac = Date.wrap_day_fraction_to_time( stop - start ) p hours, minutes, seconds, frac --00163628391a1be7c404907efbbc--