Forum: Ruby undefined method `parse' for Time:Class Error

Posted by Srikanth Jeeva (srikanth_j)
on 2008-12-09 11:54
hi,,.
i used this code ..

 Time.parse("October 20th, 2008, 7:48 pm")
got this error...

NoMethodError: undefined method `parse' for Time:Class

can any one help ,
how to install the parse method???

I'm using ruby version 1.8.6..., so no error in version
Posted by Sebastian Hungerecker (Guest)
on 2008-12-09 11:56
(Received via mailing list)
Srikanth Jeeva wrote:
> how to install the parse method???

require 'time'

HTH,
Sebastian
Posted by Srikanth Jeeva (srikanth_j)
on 2008-12-09 12:08
hey thanks .... :-)
its working now...

but when i tried.,
 Time.methods

=> ["inspect", "private_class_method", "const_missing", "clone", 
"method", "public_methods", "public_instance_methods", 
"instance_variable_defined?", "method_defined?", "superclass", "equal?", 
"freeze", "mktime", "included_modules", "const_get", "methods", 
"respond_to?", "_load", "module_eval", "class_variables", "now", "dup", 
"protected_instance_methods", "instance_variables", 
"public_method_defined?", "__id__", "eql?", "object_id", "const_set", 
"id", "at", "singleton_methods", "send", "class_eval", "taint", "utc", 
"frozen?", "instance_variable_get", "include?", 
"private_instance_methods", "__send__", "instance_of?", 
"private_method_defined?", "to_a", "name", "autoload", "type", "new", 
"<", "protected_methods", "instance_eval", "<=>", "display", "==", ">", 
"===", "instance_method", "gm", "instance_variable_set", "kind_of?", 
"extend", "protected_method_defined?", "const_defined?", ">=", 
"ancestors", "to_s", "<=", "public_class_method", "allocate", "hash", 
"class", "instance_methods", "tainted?", "=~", "private_methods", 
"class_variable_defined?", "nil?", "local", "untaint", "times", 
"constants", "is_a?", "autoload?"]

got only these & parse method  is missing ...
but in my friends PC parse method is present..

how to do it,
without using require 'Time'??
Posted by Tim Heaney (Guest)
on 2008-12-09 12:11
(Received via mailing list)
Srikanth Jeeva <sri.jjhero@gmail.com> writes:
>
> i used this code ..
>
>  Time.parse("October 20th, 2008, 7:48 pm")
> got this error...
>
> NoMethodError: undefined method `parse' for Time:Class
>
> can any one help ,
> how to install the parse method???

You can use the time module.

  irb(main):005:0> require 'time'
  => true
  irb(main):006:0> Time.parse("October 20th, 2008, 7:48 pm")
  => Mon Oct 20 19:48:00 -0400 2008
Posted by Jim McKerchar (Guest)
on 2008-12-09 16:10
(Received via mailing list)
Just to add my tuppence.... the same applies to Date.parse (amongst
other Date/Time methods). Can anyone explain why this is the case and
why some documented methods in Date and Time are only available by
requiring the respective module when other methods are available by 
default?

As i've come across this in the past i'm interested to know if there is
a reason for this. Is this the intended behaviour or is it technically a
"bug"?

Jim
Posted by Sebastian Hungerecker (Guest)
on 2008-12-09 19:57
(Received via mailing list)
Jim McKerchar wrote:
> Just to add my tuppence.... the same applies to Date.parse (amongst
> other Date/Time methods). Can anyone explain why this is the case and
> why some documented methods in Date and Time are only available by
> requiring the respective module when other methods are available by
> default?

The entire Date class is available only after requiring it. Date simply 
isn't
a core class. Why Time.parse isn't in core while Time itself is, 
however, I
do not know.
As a sidenote: there are no *modules* Time or Date.

HTH,
Sebastian
Posted by Pit Capitain (Guest)
on 2008-12-10 00:14
(Received via mailing list)
2008/12/9 Sebastian Hungerecker <sepp2k@googlemail.com>:
> As a sidenote: there are no *modules* Time or Date.

irb(main):001:0> Time.is_a? Module
=> true
irb(main):002:0> Date.is_a? Module
=> true

Regards,
Pit
Posted by Sean O'halpin (sean)
on 2008-12-10 09:04
(Received via mailing list)
On Tue, Dec 9, 2008 at 11:07 PM, Pit Capitain <pit.capitain@gmail.com> 
wrote:
>
Hate to be picky, but:

irb(main):001:0> Time.is_a? Class
=> true
irb(main):002:0> Class.is_a? Module
=> true

Regards,
Sean
Posted by Sebastian Hungerecker (Guest)
on 2008-12-10 10:07
(Received via mailing list)
Pit Capitain wrote:
> irb(main):001:0> Time.is_a? Module
> => true
> irb(main):002:0> Date.is_a? Module
> => true

I don't think it'd be useful to define the term module to mean "class or
module" because that'd make it cumbersome to differentiate between 
modules
and classes (e.g. if someone said "modules can be included into classes" 
that
wouldn't be true by that definition because classes can't be included 
into
classes).
At any rate when I said module above I used that definition of the term 
module
which does not included classes as a subset. And I do believe that so 
did the
posters I was responding to (if they didn't that was a misunderstanding 
on my
part).
Posted by Michael Fellinger (Guest)
on 2008-12-10 10:30
(Received via mailing list)
On Wed, Dec 10, 2008 at 3:50 AM, Sebastian Hungerecker
<sepp2k@googlemail.com> wrote:
> Jim McKerchar wrote:
>> Just to add my tuppence.... the same applies to Date.parse (amongst
>> other Date/Time methods). Can anyone explain why this is the case and
>> why some documented methods in Date and Time are only available by
>> requiring the respective module when other methods are available by
>> default?
>
> The entire Date class is available only after requiring it. Date simply isn't
> a core class. Why Time.parse isn't in core while Time itself is, however, I
> do not know.

The things you have to "require" are written in ruby and have the
corresponding time.rb and date.rb - the methods available before this
are the ones written in C and compiled together with ruby.

^ manveru
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.