ruby - Why is (10..20).last the same as (10...20).last -
this question has answer here:
why these 2 equivalent?
(10..20).last #=> 20 (10...20).last #=> 20
this sounds duplicate of ruby 'range.last' not give last value. why?, answers question it's design. why designed that? purpose of ..
, ...
returning same values last
when else different?
i'll answer question question: last value of 0.0...1.0
?
in general, not every range enumerable. such ranges excluded end, there no meaningful last
value other value used define end of range.
note can enumerate inclusive ranges last
is not last value enumerated!
(0..3.2).to_a.last # 3 (0..3.2).last # 3.2 (0..float::infinity).to_a.last # don't wait 1
the motivation of design "the value used define end of range" not identical "the last value enumerated range". last
gives former.
Comments
Post a Comment