unexpected error in time difference

Discussion in 'Ruby' started by Heesob Park, Nov 27, 2008.

  1. Heesob Park

    Heesob Park Guest

    Hi,

    I found some unexpected errors in time difference test.
    Is this a bug or feature?

    irb(main):001:0> Time.now-1
    => Thu Nov 27 16:19:35 +0900 2008
    irb(main):002:0> Time.now -1
    ArgumentError: wrong number of arguments (1 for 0)
    from (irb):2:in `initialize'
    from (irb):2:in `now'
    from (irb):2
    irb(main):003:0> Time.now - 1
    => Thu Nov 27 16:19:40 +0900 2008
    irb(main):004:0> t = Time.now
    => Thu Nov 27 16:19:48 +0900 2008
    irb(main):005:0> Time.now-t
    => 7.250976
    irb(main):006:0> Time.now -t
    NoMethodError: undefined method `-@' for Thu Nov 27 16:19:48 +0900 2008:Time
    from (irb):6
    from :0
    irb(main):007:0> Time.now - t
    => 11.539909

    Regards,

    Park Heesob
     
    Heesob Park, Nov 27, 2008
    #1
    1. Advertising

  2. Heesob Park

    Jorrel Guest

    If you place parentheses it's much clearer:

    Time.now().-(1)
    vs
    Time.now(-1) # wrong num of args

    On Thu, Nov 27, 2008 at 3:29 PM, Heesob Park <> wrote:
    > Hi,
    >
    > I found some unexpected errors in time difference test.
    > Is this a bug or feature?
    >
    > irb(main):001:0> Time.now-1
    > => Thu Nov 27 16:19:35 +0900 2008
    > irb(main):002:0> Time.now -1
    > ArgumentError: wrong number of arguments (1 for 0)
    > from (irb):2:in `initialize'
    > from (irb):2:in `now'
    > from (irb):2
    > irb(main):003:0> Time.now - 1
    > => Thu Nov 27 16:19:40 +0900 2008
    > irb(main):004:0> t = Time.now
    > => Thu Nov 27 16:19:48 +0900 2008
    > irb(main):005:0> Time.now-t
    > => 7.250976
    > irb(main):006:0> Time.now -t
    > NoMethodError: undefined method `-@' for Thu Nov 27 16:19:48 +0900 2008:Time
    > from (irb):6
    > from :0
    > irb(main):007:0> Time.now - t
    > => 11.539909
    >
    > Regards,
    >
    > Park Heesob
    >
    >




    --
    jorrel
     
    Jorrel, Nov 27, 2008
    #2
    1. Advertising

  3. On 27.11.2008 08:29, Heesob Park wrote:
    > I found some unexpected errors in time difference test.
    > Is this a bug or feature?
    >
    > irb(main):001:0> Time.now-1
    > => Thu Nov 27 16:19:35 +0900 2008
    > irb(main):002:0> Time.now -1
    > ArgumentError: wrong number of arguments (1 for 0)
    > from (irb):2:in `initialize'
    > from (irb):2:in `now'
    > from (irb):2
    > irb(main):003:0> Time.now - 1
    > => Thu Nov 27 16:19:40 +0900 2008
    > irb(main):004:0> t = Time.now
    > => Thu Nov 27 16:19:48 +0900 2008
    > irb(main):005:0> Time.now-t
    > => 7.250976
    > irb(main):006:0> Time.now -t
    > NoMethodError: undefined method `-@' for Thu Nov 27 16:19:48 +0900 2008:Time
    > from (irb):6
    > from :0
    > irb(main):007:0> Time.now - t
    > => 11.539909


    Works as designed. With Time.now -1 the parser parses this as
    Time.now(-1). Rule of thumb: use spaces around operators - makes your
    code also more readable.

    Kind regards

    robert
     
    Robert Klemme, Nov 27, 2008
    #3
    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. Polo Lee
    Replies:
    0
    Views:
    2,767
    Polo Lee
    Jul 7, 2003
  2. flamesrock
    Replies:
    8
    Views:
    554
    Hendrik van Rooyen
    Nov 24, 2006
  3. Franck
    Replies:
    0
    Views:
    249
    Franck
    Nov 12, 2003
  4. Vaquar
    Replies:
    1
    Views:
    237
    Vaquar
    Mar 20, 2007
  5. Ruwan Budha
    Replies:
    4
    Views:
    1,201
    Kirk Haines
    Mar 9, 2011
Loading...

Share This Page