Project

General

Profile

Actions

Feature #6670

closed

str.chars.last should be possible

Added by yhara (Yutaka HARA) over 12 years ago. Updated almost 6 years ago.

Status:
Closed
Target version:
[ruby-core:45963]

Description

=begin
Since str.chars returns an Enumerator, we need explicit to_a for some operations:

str.chars.to_a.last
str.chars.to_a[1,3]

But often I forget that and write:

str.chars.last
str.chars[1,3]

Besides that, I feel it is hard to explain why to_a is needed here when I'm writing
artilcles for Ruby beginners.

Simplest way to achieve this is to make String#chars (also #lines, #bytes and #codepoints)
return an Array. Since arrays have most of the methods defined in Enumerator, this will
not be a big change. For programs like str.chars.next, you can use each_char instead.
=end


Files

6670.pdf (39.4 KB) 6670.pdf 1-page presentation slide for the feature request meeting ([ruby-dev:45708]) yhara (Yutaka HARA), 06/30/2012 02:54 AM
string_bytes_to_array.patch (27.4 KB) string_bytes_to_array.patch zzak (zzak _), 11/19/2012 11:59 AM
0001-Deprecate-lines-bytes-chars-codepoints-of-IO-likes.patch (21.9 KB) 0001-Deprecate-lines-bytes-chars-codepoints-of-IO-likes.patch knu (Akinori MUSHA), 11/27/2012 11:56 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #7440: IO#lines etc. should return ArrayRejectedyhara (Yutaka HARA)11/26/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0