Wierd behaviour with Date

Tell me where does everything get mixed-up

site.rb:167:in `generate': undefined method `strptime' for "+2004/200":String (NoMethodError)

The offending line is

date_i=Date.strptime(date_txt,"%d.%m.%Y")

How can Date be "+2004/200"
?
On irb everything is OK.
Cheers,
V.-

···

____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.

Damphyr wrote:

Tell me where does everything get mixed-up

site.rb:167:in `generate': undefined method `strptime' for
"+2004/200":String (NoMethodError)

The offending line is

date_i=Date.strptime(date_txt,"%d.%m.%Y")

How can Date be "+2004/200"
?

Date = "+2004/200"

As easy as that... :slight_smile:

This works:

require 'date'

=> true

date_txt = "10.10.2004"

=> "10.10.2004"

Date.strptime(date_txt,"%d.%m.%Y")

=> #<Date: 4906577/2,0,2299161>

What did you do?

    robert

Robert Klemme wrote:

Damphyr wrote:

Tell me where does everything get mixed-up

site.rb:167:in `generate': undefined method `strptime' for "+2004/200":String (NoMethodError)

The offending line is

date_i=Date.strptime(date_txt,"%d.%m.%Y")

How can Date be "+2004/200" ?

Date = "+2004/200"

As easy as that... :slight_smile:

This works:

require 'date'

=> true

date_txt = "10.10.2004"

=> "10.10.2004"

Date.strptime(date_txt,"%d.%m.%Y")

=> #<Date: 4906577/2,0,2299161>

What did you do?

That's my question. And I think I found it:
If I do
class Article
  include REXML
...
end

I get the error with strptime.

If I use REXML::Document and don't include, then everything is fine.
So REXML does something to Date.
I run
ruby 1.8.2 (2004-12-25) [i386-mswin32]

Cheers,
V.-

···

____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.

Damphyr wrote:

Robert Klemme wrote:

snip

Date.strptime(date_txt,"%d.%m.%Y")

=> #<Date: 4906577/2,0,2299161>

What did you do?

That's my question. And I think I found it: If I do class Article include REXML ... ... end

I get the error with strptime.

If I use REXML::Document and don't include, then everything is fine. So REXML does something to Date.

> I run ruby 1.8.2 (2004-12-25) [i386-mswin32]

Since I cannot duplicate the problem in irb with a simple include, here's the code that duplicates this, maybe someone can see what's wrong.
Cheers,
V.-

example.xml (139 Bytes)

test.rb (1.56 KB)

···

____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.

You should not include REXML:

12:17:39 [ruby]: ruby -r date -e 'p Date.object_id; require
"rexml/document"; p Date.object_id; class X; include REXML; p
Date.object_id; end'
135087764
135087764
135679456
12:17:51 [ruby]:

Notice the different last id?

Kind regards

    robert

Robert Klemme wrote:

You should not include REXML:

12:17:39 [ruby]: ruby -r date -e 'p Date.object_id; require "rexml/document"; p Date.object_id; class X; include REXML; p Date.object_id; end' 135087764 135087764 135679456 12:17:51 [ruby]:

Notice the different last id?

Well, I figuredd that out and I run my code without the include, but the question remains, what does REXML do to Date?
'Should not include REXML when using Date' is not something that one expects, is it?
Anyway, can I call Date instead of REXML::Date?
Cheers,
V.-

···

____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.

Damphyr wrote:

Robert Klemme wrote:

You should not include REXML:

12:17:39 [ruby]: ruby -r date -e 'p Date.object_id; require
"rexml/document"; p Date.object_id; class X; include REXML; p
Date.object_id; end' 135087764 135087764 135679456 12:17:51 [ruby]:

Notice the different last id?

Well, I figuredd that out and I run my code without the include, but
the question remains, what does REXML do to Date?

IMHO REXML is not intended for inclusion it's just a namespace module. If
you import it you get all sorts of stuff inside that module into your
class. By importing it you create the effect that the namespace was
introduced to avoid.

'Should not include REXML when using Date' is not something that one
expects, is it?
Anyway, can I call Date instead of REXML::Date?

::Date

14:23:55 [ruby]: ruby -r date -e 'p Date.object_id; require
"rexml/document"; p Date.object_id; class X; include REXML; p
Date.object_id; p ::Date.ob
ject_id; end'
135087828
135087828
135677044
135087828

Kind regards

    robert