undefined method `parse' for Time:Class Error

Discussion in 'Ruby' started by Srikanth Jeeva, Dec 9, 2008.

  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
    --
    Posted via http://www.ruby-forum.com/.
     
    Srikanth Jeeva, Dec 9, 2008
    #1
    1. Advertising

  2. Srikanth Jeeva wrote:
    > how to install the parse method???


    require 'time'

    HTH,
    Sebastian
    --
    Jabber:
    ICQ: 205544826
     
    Sebastian Hungerecker, Dec 9, 2008
    #2
    1. Advertising

  3. 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 via http://www.ruby-forum.com/.
     
    Srikanth Jeeva, Dec 9, 2008
    #3
  4. 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


    Tim Heaney wrote:
    > Srikanth Jeeva <> 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
    >
    >
    > ------------------------------------------------------------------------
    >
    >
    > No virus found in this incoming message.
    > Checked by AVG - http://www.avg.com
    > Version: 8.0.176 / Virus Database: 270.9.15/1833 - Release Date: 05/12/2008 19:08
    >
    >
     
    Jim McKerchar, Dec 9, 2008
    #4
  5. 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
    --
    Jabber:
    ICQ: 205544826
     
    Sebastian Hungerecker, Dec 9, 2008
    #5
  6. Srikanth Jeeva

    Pit Capitain Guest

    2008/12/9 Sebastian Hungerecker <>:
    > 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
     
    Pit Capitain, Dec 9, 2008
    #6
  7. On Tue, Dec 9, 2008 at 11:07 PM, Pit Capitain <> wrote:
    > 2008/12/9 Sebastian Hungerecker <>:
    >> 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
    >

    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
     
    Sean O'Halpin, Dec 10, 2008
    #7
  8. 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).

    --
    Jabber:
    ICQ: 205544826
     
    Sebastian Hungerecker, Dec 10, 2008
    #8
  9. On Wed, Dec 10, 2008 at 3:50 AM, Sebastian Hungerecker
    <> 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
     
    Michael Fellinger, Dec 10, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. flamesrock
    Replies:
    8
    Views:
    469
    Hendrik van Rooyen
    Nov 24, 2006
  2. Peter Krantz
    Replies:
    2
    Views:
    196
  3. John Carter

    a=Time.now;(Time.parse(a.to_s)-a)!=0

    John Carter, Oct 26, 2007, in forum: Ruby
    Replies:
    3
    Views:
    154
    ara.t.howard
    Oct 26, 2007
  4. Paul
    Replies:
    4
    Views:
    141
    Justin Collins
    Mar 14, 2009
  5. Su Zhang
    Replies:
    3
    Views:
    215
    Su Zhang
    Apr 18, 2011
Loading...

Share This Page