[ruby-core:86570] [Ruby trunk Feature#6670][Assigned] str.chars.last should be possible

From: mame@...
Date: 2018-04-18 06:50:48 UTC
List: ruby-core #86570
Issue #6670 has been updated by mame (Yusuke Endoh).

Status changed from Closed to Assigned
Target version changed from 2.0.0 to Next Major

I have forgotten this ticket completely, and I have used `String#lines` with a block many times.
Will the methods really stop yielding each line in 3.0?  I think that the current behavior (callback only if block is given, and always return an array) is somewhat reasonable, at least, not harmful.
So, how about keeping the current behavior as is?

----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-71511

* Author: yhara (Yutaka HARA)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: Next Major
----------------------------------------
=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)
string_bytes_to_array.patch (27.4 KB)
0001-Deprecate-lines-bytes-chars-codepoints-of-IO-likes.patch (21.9 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread