Project

General

Profile

Actions

Bug #13663

closed

`String#upto` doesn't work as expected

Added by sos4nt (Stefan Schüßler) over 7 years ago. Updated almost 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
[ruby-core:81690]
Tags:

Description

Given that String#upto uses String#succ to generate successive values, I'd expect

'x'.upto('ac').to_a #=> []

to return:

["x", "y", "z", "aa", "ab", "ac"]

Instead, an empty array is returned.

This seems to depend on whether the the receiver is greater than the argument or not:

'x' <=> 'ac' #=> 1

It works just fine in this case:

'b'.upto('ca').to_a
#=> ["b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
#    "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "aa",
#    "ab", "ac", "ad", "ae", "af", "ag", "ah", "ai", "aj", "ak", "al",
#    "am", "an", "ao", "ap", "aq", "ar", "as", "at", "au", "av", "aw",
#    "ax", "ay", "az", "ba", "bb", "bc", "bd", "be", "bf", "bg", "bh",
#    "bi", "bj", "bk", "bl", "bm", "bn", "bo", "bp", "bq", "br", "bs",
#    "bt", "bu", "bv", "bw", "bx", "by", "bz", "ca"]

Presumably because of:

'b' <=> 'ca' #=> -1

Related issues 2 (0 open2 closed)

Is duplicate of Ruby master - Feature #2323: "Z".."Z".succが空Closedmatz (Yukihiro Matsumoto)Actions
Is duplicate of Ruby master - Feature #5607: Inconsistent reaction in Range of StringClosedduerst (Martin Dürst)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0