Convert date

in my irb console:
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'date'
=> false
irb(main):003:0> puts Date.parse("oct").to_s.split("-")[1]
10
=> nil

1.why
irb(main):002:0> require 'date'
=> false

2.is there more simple way to change "oct" into 10?

···

--
Posted via http://www.ruby-forum.com/.

This is odd.
Although i'd like to point out that 'Date' library is not part of rubygems
and you don't need to require 'rubygems' before requiring 'date'.
Perhaps you might want to try and require 'date' without requiring
'rubygems'...

Beyond that I would need more info regarding your setup to comment on
anything, what ruby version, what OS, how did you install ruby, etc...

···

--
Thanks & Regards,
Dhruva Sagar.

On Tue, Sep 7, 2010 at 08:51, Pen Ttt <myocean135@yahoo.cn> wrote:

in my irb console:
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'date'
=> false
irb(main):003:0> puts Date.parse("oct").to_s.split("-")[1]
10
=> nil

1.why
irb(main):002:0> require 'date'
=> false

2.is there more simple way to change "oct" into 10?
--
Posted via http://www.ruby-forum.com/\.

1.why
irb(main):002:0> require 'date'
=> false

Something already included it. Possibly something in Rubygems, possibly something irb loads automatically.

2.is there more simple way to change "oct" into 10?

irb(main):004:0> dates = {"jan" => 1, "feb" => 2, "oct" => 10}
=> {"oct"=>10, "jan"=>1, "feb"=>2}
irb(main):005:0> dates["oct"]
=> 10

Ben

···

On Sep 6, 2010, at 23:21, Pen Ttt wrote:

ruby-1.9.2-p0 > Date.parse('oct').month
=> 10

Gary Wright

···

On Sep 6, 2010, at 11:21 PM, Pen Ttt wrote:

2.is there more simple way to change "oct" into 10?

ubuntu10.04
pt@pt-laptop:~$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
sudo apt-get install ruby-full

···

--
Posted via http://www.ruby-forum.com/.

09:41:43 ~$ allruby -r date -e 'p Date.parse("oct").month'
CYGWIN_NT-5.1 padrklemme2 1.7.7(0.230/5/3) 2010-08-31 09:58 i686 Cygwin

···

On Tue, Sep 7, 2010 at 8:07 AM, Gary Wright <gwtmp01@mac.com> wrote:

On Sep 6, 2010, at 11:21 PM, Pen Ttt wrote:

2.is there more simple way to change "oct" into 10?

ruby-1.9.2-p0 > Date.parse('oct').month
=> 10

========================================
ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]
10

ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-cygwin]
10

jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java
HotSpot(TM) Client VM 1.6.0_21) [x86-java]
10
09:41:56 ~$

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

or

    months = %w{jan feb mar apr may jun jul aug sep oct nov dec}
    num = months.find_index('oct') + 1

···

At 2010-09-07 01:47AM, "Ben Giddings" wrote:

On Sep 6, 2010, at 23:21, Pen Ttt wrote:
> 2.is there more simple way to change "oct" into 10?

irb(main):004:0> dates = {"jan" => 1, "feb" => 2, "oct" => 10}
=> {"oct"=>10, "jan"=>1, "feb"=>2}
irb(main):005:0> dates["oct"]
=> 10

--
Glenn Jackman
    Write a wise saying and your name will live forever. -- Anonymous