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?

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 S…

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

On Sep 6, 2010, at 23:21, Pen T. wrote:

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 11:21 PM, Pen T. wrote:

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

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

Gary W.

At 2010-09-07 01:47AM, “Ben G.” wrote:

On Sep 6, 2010, at 23:21, Pen T. 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

or

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

On Tue, Sep 7, 2010 at 8:07 AM, Gary W. [email protected] wrote:

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

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

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

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

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™ Client VM 1.6.0_21) [x86-java]
10
09:41:56 ~$

Cheers

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs