Undefined method `parse' for Time:Class Error

#1

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

#2

Srikanth J. wrote:

how to install the parse method???

require ‘time’

HTH,
Sebastian

#3

hey thanks … :slight_smile:
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’??

#4

Srikanth J. removed_email_address@domain.invalid 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

#5

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

#6

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

#7

2008/12/9 Sebastian H. removed_email_address@domain.invalid:

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

#8

Pit C. 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).

#9

On Tue, Dec 9, 2008 at 11:07 PM, Pit C. removed_email_address@domain.invalid
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

#10

On Wed, Dec 10, 2008 at 3:50 AM, Sebastian H.
removed_email_address@domain.invalid 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