undefined method `parse' for Time:Class Error

S

Srikanth Jeeva

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
 
S

Srikanth Jeeva

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'??
 
J

Jim McKerchar

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
 
S

Sebastian Hungerecker

Jim said:
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
 
P

Pit Capitain

2008/12/9 Sebastian Hungerecker said:
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
 
S

Sean O'Halpin

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

Regards,
Pit
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
 
S

Sebastian Hungerecker

Pit said:
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).
 
M

Michael Fellinger

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
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top