convert date

P

Pen Ttt

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?
 
D

Dhruva Sagar

[Note: parts of this message were removed to make it a legal post.]

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

Pen Ttt

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

Ben Giddings

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
 
R

Robert Klemme

ruby-1.9.2-p0 > =A0 Date.parse('oct').month
=A0=3D> 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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]
10
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-cygwin]
10
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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



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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top