[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Super return changed in 1.8.6

Han Holl

7/3/2007 2:01:00 PM

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

4 Answers

Gregory Brown

7/3/2007 3:32:00 PM

0

On 7/3/07, Han Holl <han.holl@gmail.com> wrote:
> 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/v...

" * date

* Updated based on date2 4.0.3. "

I've not investigated further.

Han Holl

7/4/2007 2:15:00 PM

0

On 7/3/07, Gregory Brown <gregory.t.brown@gmail.com> wrote:
> It looks like perhaps the date library has changed in 1.8.6
>
> http://svn.ruby-lang.org/repos/ruby/tags/v...
>
> " * date
>
> * Updated based on date2 4.0.3. "
>
> I've not investigated further.
>
>
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.

Cheers,

Han Holl

Gregory Brown

7/4/2007 2:30:00 PM

0

On 7/4/07, Han Holl <han.holl@gmail.com> wrote:

> 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...

Gregor Schmidt

7/4/2007 3:46:00 PM

0

> 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