[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: simple operations
From: "Frank J. Cameron" <fjc () fastmail ! net>
Date: 2021-09-27 14:21:57
Message-ID: CACEKW=JHWuSa08kFZTBXjDeE46=TOTiYyXC9oaabGAZg8hw0Kg () mail ! gmail ! com
[Download RAW message or body]
On 9/27/21, Stefano Crocco <stefano.crocco@alice.it> wrote:
> On lunedì 27 settembre 2021 14:53:22 CEST Die Optimisten wrote:
>> Date.today
>> Date.today +1 # no error, but wrong result!
>
> Which kind of wrong result do you get? For me (ruby 2.6.8), it seems to work
> as expected:
>
> Date.today.strftime
> => 2021-09-27
> (Date.today+1).strftime
> => 2021-09-28
Parsing depends on the spaces:
Adding "one":
Date.today+1
Date.today_+_1
vs
Argument "one":
Date.today_+1
Date.today_1
Date.today(+1)
Date.today(1)
irb(main):013:0> (Date.today).strftime
=> "2021-09-27"
irb(main):014:0> (Date.today+1).strftime
=> "2021-09-28"
irb(main):015:0> (Date.today +1).strftime
=> "2021-09-27"
irb(main):016:0> (Date.today(+1)).strftime
=> "2021-09-27"
irb(main):017:0> (Date.today(1)).strftime
=> "2021-09-27"
irb(main):018:0> (Date.today 1).strftime
=> "2021-09-27"
$ ruby -r parser/current -e 'p Parser::CurrentRuby.parse("Date.today +1")'
s(:send,
s(:const, nil, :Date), :today,
s(:int, 1))
$ ruby -r parser/current -e 'p Parser::CurrentRuby.parse("Date.today+1")'
s(:send,
s(:send,
s(:const, nil, :Date), :today), :+,
s(:int, 1))
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic