From: dblack@... Date: 2006-11-27T07:22:53+09:00 Subject: Re: REXML and Date interaction Hi -- On Mon, 27 Nov 2006, Robert Evans wrote: > Hi, > > Thanks for running it, indeed that broken version works, and I must've > corrupted my irb session. So, I tried it again and discovered more precisely > the problem. If I include REXML in the class instead of explicitly specifying > REXML::Document, then I get the problem. Which, I can just "not do that" for > now, but it is still curious what is happening. Here is a version that seems > to produce the error still. > > Thanks for the sanity check, > > Bob Evans > > > > Better Broken > ============= > #!/usr/bin/env ruby > > require 'rexml/document' > require 'date' > > class DateFun > ## BEGIN Different > include REXML > ## END Different > > def parse(xml) > ## BEGIN Different > doc = Document.new(xml) > ##End Different > > elems = doc.root.get_elements('//body/dateelement[@date]') > elems.map { |s| > s.attributes["date"].to_s > }.sort > end > > def sorted_dates_from(xml) > sorted_dates = parse(xml) > sorted_dates.map { |d| Date.parse(d)}.sort What's happening is that you're bringing REXML::Date into scope. You need to do: ::Date.parse to get the top-level Date constant. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org