Super return changed in 1.8.6

H

Han Holl

Hello,

The following snippet:

#!/usr/bin/ruby -w
require 'date'
class MyDate < Date
def self.today
super
end
end
puts MyDate.today.class
## end

prints out 'MyDate' with ruby 1.8.4 and 1.8.5, but 'Date' with 1.8.6

Is this a bug in 1.8.6, or the correction of a long lived bug in
versions before ?

Cheers,

Han Holl
 
G

Gregory Brown

Hello,

The following snippet:

#!/usr/bin/ruby -w
require 'date'
class MyDate < Date
def self.today
super
end
end
puts MyDate.today.class
## end

prints out 'MyDate' with ruby 1.8.4 and 1.8.5, but 'Date' with 1.8.6

Is this a bug in 1.8.6, or the correction of a long lived bug in
versions before ?

It looks like perhaps the date library has changed in 1.8.6

http://svn.ruby-lang.org/repos/ruby/tags/v1_8_6/NEWS

" * date

* Updated based on date2 4.0.3. "

I've not investigated further.
 
G

Gregory Brown

Indeed.
My question was whether this should be considered a bug: #today is
kind of a specialized version of #new, so I would expect the
implementation to be #new like, and return a MyDate.

That sounds to me like someone used Date.new instead of self.new in
class method somewhere. :)

And yeah, I'd look at it as a bug too. As a workaround, you can
probably do a manual conversion...
 
G

Gregor Schmidt

And yeah, I'd look at it as a bug too. As a workaround, you can
probably do a manual conversion...

Or actually fix the problem ;-)

This is the source of Date.today, found in the docs:

def self.today(sg=ITALY)
Time.now.__send__:)to_date).new_start(sg)
end

This obviously causes your the bug. My first idea to fix this feature
would be

def self.today(sg=ITALY)
self.parse(Time.now.to_s, false, sg)
end

It works, but I guess, it is not really efficient.

By the way:
Is there a special reason, I never understood, why to_date on Time
became private in 1.8.6?

Cheers,

Gregor Schmidt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,096
Latest member
ThurmanCre

Latest Threads

Top