ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible
@ 2012-06-29 17:52 yhara (Yutaka HARA)
  2012-06-29 17:54 ` [ruby-core:45964] [ruby-trunk - Feature #6670] " yhara (Yutaka HARA)
                   ` (34 more replies)
  0 siblings, 35 replies; 36+ messages in thread
From: yhara (Yutaka HARA) @ 2012-06-29 17:52 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been reported by yhara (Yutaka HARA).

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

Author: yhara (Yutaka HARA)
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:45964] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
@ 2012-06-29 17:54 ` yhara (Yutaka HARA)
  2012-07-01 16:41 ` [ruby-core:46061] [ruby-trunk - Feature #6670][Assigned] " mame (Yusuke Endoh)
                   ` (33 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: yhara (Yutaka HARA) @ 2012-06-29 17:54 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by yhara (Yutaka HARA).

File 6670.pdf added

Adding presentation slide for the feature request meeting ([ruby-dev:45708])
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-27568

Author: yhara (Yutaka HARA)
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:46061] [ruby-trunk - Feature #6670][Assigned] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
  2012-06-29 17:54 ` [ruby-core:45964] [ruby-trunk - Feature #6670] " yhara (Yutaka HARA)
@ 2012-07-01 16:41 ` mame (Yusuke Endoh)
  2012-07-01 17:59 ` [ruby-core:46077] [ruby-trunk - Feature #6670] " trans (Thomas Sawyer)
                   ` (32 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: mame (Yusuke Endoh) @ 2012-07-01 16:41 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)

Received.  Thank you!

You really want just #last?

-- 
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-27669

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:46077] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
  2012-06-29 17:54 ` [ruby-core:45964] [ruby-trunk - Feature #6670] " yhara (Yutaka HARA)
  2012-07-01 16:41 ` [ruby-core:46061] [ruby-trunk - Feature #6670][Assigned] " mame (Yusuke Endoh)
@ 2012-07-01 17:59 ` trans (Thomas Sawyer)
  2012-07-02  3:07 ` [ruby-core:46097] " marcandre (Marc-Andre Lafortune)
                   ` (31 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: trans (Thomas Sawyer) @ 2012-07-01 17:59 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by trans (Thomas Sawyer).


While I realize it doesn't exactly fit with the whole iteration thing particularly well, I nonetheless do not think it's unreasonable for Enumerator to support something like #last(n=1). In most cases that just means it has to iterate on down to the end and deliver the result. In some cases it might be able to optimize, say if the enumerable has a fixed size.

This issue might also have some relation to the issue about Enumerable#size, #6636.

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

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:46097] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (2 preceding siblings ...)
  2012-07-01 17:59 ` [ruby-core:46077] [ruby-trunk - Feature #6670] " trans (Thomas Sawyer)
@ 2012-07-02  3:07 ` marcandre (Marc-Andre Lafortune)
  2012-07-24 13:54 ` [ruby-core:46728] " mame (Yusuke Endoh)
                   ` (30 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: marcandre (Marc-Andre Lafortune) @ 2012-07-02  3:07 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by marcandre (Marc-Andre Lafortune).


Hi,

trans (Thomas Sawyer) wrote:
> This issue might also have some relation to the issue about Enumerable#size, #6636.

Not directly. Being able to calculate lazily a size does not mean it is easy to have random access, and the api I propose would be quite a bit more complicated if it was to allow for random access.

I feel that the lack of #last is a good thing. It's there to remind you that it might be expensive, and that (for example) it would be worth storing in a local var instead of calling it twice...

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

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:46728] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (3 preceding siblings ...)
  2012-07-02  3:07 ` [ruby-core:46097] " marcandre (Marc-Andre Lafortune)
@ 2012-07-24 13:54 ` mame (Yusuke Endoh)
  2012-08-03 10:53 ` [ruby-core:46960] " yhara (Yutaka HARA)
                   ` (29 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: mame (Yusuke Endoh) @ 2012-07-24 13:54 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by mame (Yusuke Endoh).

Assignee changed from matz (Yukihiro Matsumoto) to yhara (Yutaka HARA)

Yutaka Hara,

I'm happy to inform you that matz has accepted your proposal,
as making #chars, #lines, etc. return an Array (and keep
#each_char, etc as is).

  "foo".chars     #=> ["f", "o", "o"]
  "foo".each_char #=> #<Enumerator: "foo":each_char>

Yhara-san, could you create a patch?

-- 
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-28395

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:46960] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (4 preceding siblings ...)
  2012-07-24 13:54 ` [ruby-core:46728] " mame (Yusuke Endoh)
@ 2012-08-03 10:53 ` yhara (Yutaka HARA)
  2012-08-15 12:30 ` [ruby-core:47212] " yhara (Yutaka HARA)
                   ` (28 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: yhara (Yutaka HARA) @ 2012-08-03 10:53 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by yhara (Yutaka HARA).


> I'm happy to inform you that matz has accepted your proposal,
> as making #chars, #lines, etc. return an Array (and keep
> #each_char, etc as is).

Thank you. I'm happy too :-)

I will make a patch in this weekend.
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-28623

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:47212] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (5 preceding siblings ...)
  2012-08-03 10:53 ` [ruby-core:46960] " yhara (Yutaka HARA)
@ 2012-08-15 12:30 ` yhara (Yutaka HARA)
  2012-10-26 22:13 ` [ruby-core:48381] " ko1 (Koichi Sasada)
                   ` (27 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: yhara (Yutaka HARA) @ 2012-08-15 12:30 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by yhara (Yutaka HARA).


=begin
Hello,

I wrote a patch for String#lines, #chars, #bytes and #codepoints.

* https://github.com/ruby/ruby/pull/158.diff

Seemingly the following methods also need to be fixed (right?)

* IO#lines, chars, bytes, codepoints
* StringIO#lines, chars, bytes, codepoints
* ARGF.lines, chars, bytes
  * Is it intentional that ARGF.codepoints is missing?
=end

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

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:48381] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (6 preceding siblings ...)
  2012-08-15 12:30 ` [ruby-core:47212] " yhara (Yutaka HARA)
@ 2012-10-26 22:13 ` ko1 (Koichi Sasada)
  2012-10-29  8:43 ` [ruby-core:48540] " knu (Akinori MUSHA)
                   ` (26 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: ko1 (Koichi Sasada) @ 2012-10-26 22:13 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by ko1 (Koichi Sasada).


ping.
status?

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

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:48540] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (7 preceding siblings ...)
  2012-10-26 22:13 ` [ruby-core:48381] " ko1 (Koichi Sasada)
@ 2012-10-29  8:43 ` knu (Akinori MUSHA)
  2012-11-19  2:59 ` [ruby-core:49551] " zzak (Zachary Scott)
                   ` (25 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: knu (Akinori MUSHA) @ 2012-10-29  8:43 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by knu (Akinori MUSHA).


If #lines is to become no longer an alias for #each_line, there should be no point in supporting lines {} any more.  It should emit a deprecation warning and get unsupported in the future.
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-31910

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:49551] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (8 preceding siblings ...)
  2012-10-29  8:43 ` [ruby-core:48540] " knu (Akinori MUSHA)
@ 2012-11-19  2:59 ` zzak (Zachary Scott)
  2012-11-19 18:14 ` [ruby-core:49601] " mame (Yusuke Endoh)
                   ` (24 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: zzak (Zachary Scott) @ 2012-11-19  2:59 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by zzak (Zachary Scott).

File string_bytes_to_array.patch added
Assignee changed from yhara (Yutaka HARA) to mame (Yusuke Endoh)

I've added Yukata-san's patch from github, please continue discussion here.

mame, could you please review this?
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-33075

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: mame (Yusuke Endoh)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:49601] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (9 preceding siblings ...)
  2012-11-19  2:59 ` [ruby-core:49551] " zzak (Zachary Scott)
@ 2012-11-19 18:14 ` mame (Yusuke Endoh)
  2012-11-24  2:16 ` [ruby-core:49970] " mame (Yusuke Endoh)
                   ` (23 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: mame (Yusuke Endoh) @ 2012-11-19 18:14 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by mame (Yusuke Endoh).

Assignee changed from mame (Yusuke Endoh) to knu (Akinori MUSHA)

knu, could you please review this? :-)

-- 
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-33117

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: knu (Akinori MUSHA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:49970] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (10 preceding siblings ...)
  2012-11-19 18:14 ` [ruby-core:49601] " mame (Yusuke Endoh)
@ 2012-11-24  2:16 ` mame (Yusuke Endoh)
  2012-11-24 10:38 ` [ruby-core:50035] " knu (Akinori MUSHA)
                   ` (22 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: mame (Yusuke Endoh) @ 2012-11-24  2:16 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by mame (Yusuke Endoh).

Assignee changed from knu (Akinori MUSHA) to nagachika (Tomoyuki Chikanaga)

nagachika-san, could you please review this?

-- 
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-33736

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: nagachika (Tomoyuki Chikanaga)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50035] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (11 preceding siblings ...)
  2012-11-24  2:16 ` [ruby-core:49970] " mame (Yusuke Endoh)
@ 2012-11-24 10:38 ` knu (Akinori MUSHA)
  2012-11-24 13:18 ` [ruby-core:50039] " nagachika (Tomoyuki Chikanaga)
                   ` (21 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: knu (Akinori MUSHA) @ 2012-11-24 10:38 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by knu (Akinori MUSHA).


Sorry, my mail filter was so buggy I failed to be notified.

I've reviewed and already given a comment above, and another on Twitter that yieldp can be dropped in favor of NIL_P(ary), without any of them responded to.
Should I revise the patch myself?
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-33811

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: nagachika (Tomoyuki Chikanaga)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50039] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (12 preceding siblings ...)
  2012-11-24 10:38 ` [ruby-core:50035] " knu (Akinori MUSHA)
@ 2012-11-24 13:18 ` nagachika (Tomoyuki Chikanaga)
  2012-11-24 13:24 ` [ruby-core:50040] " mame (Yusuke Endoh)
                   ` (20 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: nagachika (Tomoyuki Chikanaga) @ 2012-11-24 13:18 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by nagachika (Tomoyuki Chikanaga).

Assignee changed from nagachika (Tomoyuki Chikanaga) to knu (Akinori MUSHA)

Hello,
Sorry for late reply.

OK, I assign this ticket to knu san again.
Anyway I'm willing to review the patch :)

BTW, I cannot apply string_bytes_to_array.patch on trunk r37835.
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-33816

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: knu (Akinori MUSHA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50040] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (13 preceding siblings ...)
  2012-11-24 13:18 ` [ruby-core:50039] " nagachika (Tomoyuki Chikanaga)
@ 2012-11-24 13:24 ` mame (Yusuke Endoh)
  2012-11-25 17:23 ` [ruby-core:50082] " brixen (Brian Ford)
                   ` (19 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: mame (Yusuke Endoh) @ 2012-11-24 13:24 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by mame (Yusuke Endoh).


Thanks!

> Should I revise the patch myself?

Could you do it, please?
If you are not willing, please pass the ball to nagachika-san.

-- 
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-33817

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: knu (Akinori MUSHA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50082] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (14 preceding siblings ...)
  2012-11-24 13:24 ` [ruby-core:50040] " mame (Yusuke Endoh)
@ 2012-11-25 17:23 ` brixen (Brian Ford)
  2012-11-25 21:01 ` [ruby-core:50091] " drbrain (Eric Hodel)
                   ` (18 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: brixen (Brian Ford) @ 2012-11-25 17:23 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by brixen (Brian Ford).


What about IO, StringIO, ARGF as mentioned above?

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

Author: yhara (Yutaka HARA)
Status: Closed
Priority: Normal
Assignee: knu (Akinori MUSHA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50091] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (15 preceding siblings ...)
  2012-11-25 17:23 ` [ruby-core:50082] " brixen (Brian Ford)
@ 2012-11-25 21:01 ` drbrain (Eric Hodel)
  2012-11-26 20:36 ` [ruby-core:50179] [ruby-trunk - Feature #6670][Assigned] " naruse (Yui NARUSE)
                   ` (17 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: drbrain (Eric Hodel) @ 2012-11-25 21:01 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by drbrain (Eric Hodel).


=begin
An IO may be infinite (({open "/dev/zero" do |io| io.chars.to_a }})), and so may ARGF ((%ruby -e 'ARGF.chars.to_a' /dev/zero%)).

It doesn't make sense to add it to StringIO, but you make work around the omission through StringIO#string.
=end

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

Author: yhara (Yutaka HARA)
Status: Closed
Priority: Normal
Assignee: knu (Akinori MUSHA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50179] [ruby-trunk - Feature #6670][Assigned] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (16 preceding siblings ...)
  2012-11-25 21:01 ` [ruby-core:50091] " drbrain (Eric Hodel)
@ 2012-11-26 20:36 ` naruse (Yui NARUSE)
  2012-11-26 23:15 ` [ruby-core:50184] [ruby-trunk - Feature #6670] " marcandre (Marc-Andre Lafortune)
                   ` (16 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: naruse (Yui NARUSE) @ 2012-11-26 20:36 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by naruse (Yui NARUSE).

Status changed from Closed to Assigned
Assignee changed from knu (Akinori MUSHA) to matz (Yukihiro Matsumoto)

Now we have Enumerable#size, so we can know whether the last character is available or not by it.
So how about changing String#chars to not Array but Enumerator with size and define last method?
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-33981

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50184] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (17 preceding siblings ...)
  2012-11-26 20:36 ` [ruby-core:50179] [ruby-trunk - Feature #6670][Assigned] " naruse (Yui NARUSE)
@ 2012-11-26 23:15 ` marcandre (Marc-Andre Lafortune)
  2012-11-27  3:21 ` [ruby-core:50192] " mame (Yusuke Endoh)
                   ` (15 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: marcandre (Marc-Andre Lafortune) @ 2012-11-26 23:15 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by marcandre (Marc-Andre Lafortune).


#size will return `nil` for all enumerators based on IO.

Maybe the best is to have `chars` return an array for strings and deprecate it with a warning for IO.
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-33989

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50192] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (18 preceding siblings ...)
  2012-11-26 23:15 ` [ruby-core:50184] [ruby-trunk - Feature #6670] " marcandre (Marc-Andre Lafortune)
@ 2012-11-27  3:21 ` mame (Yusuke Endoh)
  2012-11-27 11:14 ` [ruby-core:50219] " knu (Akinori MUSHA)
                   ` (14 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: mame (Yusuke Endoh) @ 2012-11-27  3:21 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by mame (Yusuke Endoh).

Assignee changed from matz (Yukihiro Matsumoto) to yhara (Yutaka HARA)

Okay, I understand that it may be harmful to change the behavior right now.
Then, let's warn a user to use `each_line' instead in 2.0.0, and change it in future.

Yhara-san, could you create the following type of patch for all methods?


diff --git a/io.c b/io.c
index bacc6fc..26d3970 100644
--- a/io.c
+++ b/io.c
@@ -10795,6 +10795,13 @@ argf_each_line(int argc, VALUE *argv, VALUE argf)
     }
 }

+static VALUE
+argf_lines(int argc, VALUE *argv, VALUE argf)
+{
+    rb_warn("ARGF#lines will return an Array in future; you should use `each_line' instead");
+    return argf_each_line(argc, argv, argf);
+}
+
 /*
  *  call-seq:
  *     ARGF.bytes     {|byte| block }  -> ARGF
@@ -11557,7 +11564,7 @@ Init_IO(void)
     rb_define_method(rb_cARGF, "each_line",  argf_each_line, -1);
     rb_define_method(rb_cARGF, "each_byte",  argf_each_byte, 0);
     rb_define_method(rb_cARGF, "each_char",  argf_each_char, 0);
-    rb_define_method(rb_cARGF, "lines", argf_each_line, -1);
+    rb_define_method(rb_cARGF, "lines", argf_lines, -1);
     rb_define_method(rb_cARGF, "bytes", argf_each_byte, 0);
     rb_define_method(rb_cARGF, "chars", argf_each_char, 0);

-- 
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-34003

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [ruby-core:50219] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (19 preceding siblings ...)
  2012-11-27  3:21 ` [ruby-core:50192] " mame (Yusuke Endoh)
@ 2012-11-27 11:14 ` knu (Akinori MUSHA)
  2012-11-27 13:21 ` [ruby-core:50222] " trans (Thomas Sawyer)
                   ` (13 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: knu (Akinori MUSHA) @ 2012-11-27 11:14 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by knu (Akinori MUSHA).


It may be an idea to simply obsolete IO#{lines,chars,codepoints,bytes} for now.

First of all, line wise operation is known to be popular and we've already got #readlines since a long time ago.
So, there is no need for a new IO#lines that returns an array unlike String.

For chars, codepoints and bytes, there is no known need for turning a whole file or stream into an on-memory array because we haven't offered such methods to date.
That may be because character or byte wise operation on a stream is typically done using a seek pointer as it reads lazily.
If this should be the case, we don't have an urge need for a new IO#chars, #codepoints or #bytes.
However, we, including matz, confirmed in this issue that a method that does not return an array having a name in the plural form is not intuitive because most Enumerator method have a name consisting of each_ + singular noun, and lines etc. are breaking that convention.

So, what about simply obsoleting IO#{lines,chars,codepoints,bytes} in the current shape?

We can re-add them later in another shape perhaps after we introduce an indexable enumerator (lazy array) that would satisfy everyone who might take both performance and intuitiveness seriously.
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-34030

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50222] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (20 preceding siblings ...)
  2012-11-27 11:14 ` [ruby-core:50219] " knu (Akinori MUSHA)
@ 2012-11-27 13:21 ` trans (Thomas Sawyer)
  2012-11-27 14:56 ` [ruby-core:50228] " knu (Akinori MUSHA)
                   ` (12 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: trans (Thomas Sawyer) @ 2012-11-27 13:21 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by trans (Thomas Sawyer).


If I understand correctly, this is going to break a lot of code?

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

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50228] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (21 preceding siblings ...)
  2012-11-27 13:21 ` [ruby-core:50222] " trans (Thomas Sawyer)
@ 2012-11-27 14:56 ` knu (Akinori MUSHA)
  2012-11-27 16:32 ` [ruby-core:50231] " yhara (Yutaka HARA)
                   ` (11 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: knu (Akinori MUSHA) @ 2012-11-27 14:56 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by knu (Akinori MUSHA).

File 0001-Deprecate-lines-bytes-chars-codepoints-of-IO-likes.patch added

Here's a patch to deprecate #lines, #bytes, #chars and #codepoints of IO-likes.
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-34045

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50231] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (22 preceding siblings ...)
  2012-11-27 14:56 ` [ruby-core:50228] " knu (Akinori MUSHA)
@ 2012-11-27 16:32 ` yhara (Yutaka HARA)
  2012-11-28  0:38 ` [ruby-core:50238] " duerst (Martin Dürst)
                   ` (10 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: yhara (Yutaka HARA) @ 2012-11-27 16:32 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by yhara (Yutaka HARA).


trans (Thomas Sawyer) wrote:
> If I understand correctly, this is going to break a lot of code?

For String, the impact will be limited.

* String#lines returns Array, which has most of the methods defined in Enumerator.

* Exceptions are #next, #peek, #with_index, etc.
  If you have a code like `str.lines.with_index', you need to change it to `str.each_line.with_index'.

* When you have a huge string, `str.lines' will become slower and consume more memory.
  I think this is a rare case because we usually avoid `File.read(path_to_huge_file)'.
  Even when you really need huge_str.lines to return Enumerator, you can use huge_str.each_line instead.

For IO/StringIO/ARGF/GzipReader, I'd like to +1 for showing deprecation warning in 2.0.0.
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-34050

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50238] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (23 preceding siblings ...)
  2012-11-27 16:32 ` [ruby-core:50231] " yhara (Yutaka HARA)
@ 2012-11-28  0:38 ` duerst (Martin Dürst)
  2012-11-28  3:20 ` [ruby-core:50241] " yhara (Yutaka HARA)
                   ` (9 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: duerst (Martin Dürst) @ 2012-11-28  0:38 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by duerst (Martin Dürst).


Instead of this proposal, what about adding some/most/all of the Array methods to Enumerator?

E.g. like so:

module Enumerator
  def [] (pos)
    to_a[pos]
  end
end

Of course, this is just the simplest case of [], and the simplest (and maybe slowest) implementation. This is just an idea, but I think it would be way better than having to distinguish lines/each_line, chars/each_char,... and so on.
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-34060

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50241] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (24 preceding siblings ...)
  2012-11-28  0:38 ` [ruby-core:50238] " duerst (Martin Dürst)
@ 2012-11-28  3:20 ` yhara (Yutaka HARA)
  2012-11-29  5:13 ` [ruby-core:50298] " duerst (Martin Dürst)
                   ` (8 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: yhara (Yutaka HARA) @ 2012-11-28  3:20 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by yhara (Yutaka HARA).


duerst (Martin Dürst) wrote:
> Instead of this proposal, what about adding some/most/all of the Array methods to Enumerator?

It is not easy to define behavior of Enumerator#[].
For example:

  File.open(path){|f|
    ls = f.lines
    p lines[0]   #=> Prints first line
    p lines[0]   #=> Prints nil, if #[] is equivalent to #to_a[pos]
  }
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-34063

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50298] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (25 preceding siblings ...)
  2012-11-28  3:20 ` [ruby-core:50241] " yhara (Yutaka HARA)
@ 2012-11-29  5:13 ` duerst (Martin Dürst)
  2012-11-29  8:12 ` [ruby-core:50305] " knu (Akinori MUSHA)
                   ` (7 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: duerst (Martin Dürst) @ 2012-11-29  5:13 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by duerst (Martin Dürst).


yhara (Yutaka HARA) wrote:

> For String, the impact will be limited.
> 
> * String#lines returns Array, which has most of the methods defined in Enumerator.
> 
> * Exceptions are #next, #peek, #with_index, etc.
>   If you have a code like `str.lines.with_index', you need to change it to `str.each_line.with_index'.

For with_index in particular, wouldn't it make sense to either add it to Enumerable or deprecate it on Enumerator? That would eliminate one more difference.

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

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50305] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (26 preceding siblings ...)
  2012-11-29  5:13 ` [ruby-core:50298] " duerst (Martin Dürst)
@ 2012-11-29  8:12 ` knu (Akinori MUSHA)
  2012-11-30  9:08 ` [ruby-core:50378] " yhara (Yutaka HARA)
                   ` (6 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: knu (Akinori MUSHA) @ 2012-11-29  8:12 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by knu (Akinori MUSHA).

Assignee changed from yhara (Yutaka HARA) to matz (Yukihiro Matsumoto)

We don't have much time left before 2.0 to decide how to change IO#lines, #chars, etc. .
Can we deprecate them for now as a first step as proposed above?
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-34129

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50378] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (27 preceding siblings ...)
  2012-11-29  8:12 ` [ruby-core:50305] " knu (Akinori MUSHA)
@ 2012-11-30  9:08 ` yhara (Yutaka HARA)
  2012-11-30 16:28 ` [ruby-core:50399] " drbrain (Eric Hodel)
                   ` (5 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: yhara (Yutaka HARA) @ 2012-11-30  9:08 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by yhara (Yutaka HARA).


knu (Akinori MUSHA) wrote:
> Here's a patch to deprecate #lines, #bytes, #chars and #codepoints of IO-likes.

Maybe we can change StringIO#lines to return Array now because it does not have problems like IO and ARGF.
(problems = return value of IO#lines may be huge or even infinite)


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

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50399] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (28 preceding siblings ...)
  2012-11-30  9:08 ` [ruby-core:50378] " yhara (Yutaka HARA)
@ 2012-11-30 16:28 ` drbrain (Eric Hodel)
  2012-11-30 17:02 ` [ruby-core:50401] " yhara (Yutaka HARA)
                   ` (4 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: drbrain (Eric Hodel) @ 2012-11-30 16:28 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by drbrain (Eric Hodel).


I often use StringIO as an IO substitute for tests. I would prefer matching behavior.

You can get the last line by stringio.string.lines.last. Is this acceptable?
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-34226

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:50401] [ruby-trunk - Feature #6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (29 preceding siblings ...)
  2012-11-30 16:28 ` [ruby-core:50399] " drbrain (Eric Hodel)
@ 2012-11-30 17:02 ` yhara (Yutaka HARA)
  2018-04-18  6:50 ` [ruby-core:86570] [Ruby trunk Feature#6670][Assigned] " mame
                   ` (3 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: yhara (Yutaka HARA) @ 2012-11-30 17:02 UTC (permalink / raw
  To: ruby-core


Issue #6670 has been updated by yhara (Yutaka HARA).


duerst (Martin Dürst) wrote:
> For with_index in particular, wouldn't it make sense to either add it to Enumerable or deprecate it on Enumerator? That would eliminate one more difference.

If we add Enumerable#with_index, we could write str.with_index. This does not make sense becuase String#each is not defined.

drbrain (Eric Hodel) wrote:
> I often use StringIO as an IO substitute for tests. I would prefer matching behavior.
> 
> You can get the last line by stringio.string.lines.last. Is this acceptable?

Yes. And I got a reply from @knu: https://twitter.com/knu/status/274442544518156288
He said "We should not fix API of StringIO before fixing that of IO" and I agreed.
----------------------------------------
Feature #6670: str.chars.last should be possible
https://bugs.ruby-lang.org/issues/6670#change-34228

Author: yhara (Yutaka HARA)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=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



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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:86570] [Ruby trunk Feature#6670][Assigned] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (30 preceding siblings ...)
  2012-11-30 17:02 ` [ruby-core:50401] " yhara (Yutaka HARA)
@ 2018-04-18  6:50 ` mame
  2018-04-18 16:54 ` [ruby-core:86584] [Ruby trunk Feature#6670] " shevegen
                   ` (2 subsequent siblings)
  34 siblings, 0 replies; 36+ messages in thread
From: mame @ 2018-04-18  6:50 UTC (permalink / raw
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:86584] [Ruby trunk Feature#6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (31 preceding siblings ...)
  2018-04-18  6:50 ` [ruby-core:86570] [Ruby trunk Feature#6670][Assigned] " mame
@ 2018-04-18 16:54 ` shevegen
  2018-12-26  8:24 ` [ruby-core:90728] " mame
  2018-12-26 14:31 ` [ruby-core:90731] [Ruby trunk Feature#6670][Closed] " mame
  34 siblings, 0 replies; 36+ messages in thread
From: shevegen @ 2018-04-18 16:54 UTC (permalink / raw
  To: ruby-core

Issue #6670 has been updated by shevegen (Robert A. Heiler).


While I myself have not needed str.chars.last, I can understand
why Yutaka HARA suggested it. Makes sense to me personally-

One comment on this:

> I feel that the lack of #last is a good thing. It's there
> to remind you that it might be expensive, and that (for
> example) it would be worth storing in a local var instead
> of calling it twice.

In general, in ruby, speed considerations are not the first
typical thought that may come to every ruby hacker. And there
is a big difference between (a) something that is slow, but
possible, and (b) something that may be slow, but is not 
possible. I think in this case, (a) applies and the speed
consideration comes (or should come) secondary - so I don't
feel that using speed as an example, should be something that
speaks against the proposal itself. IMO the question should
be whether this is sufficiently useful or not. I can't answer
this either, but from that point of view, I think the proposal
by Yutaka HARA makes sense. Matz will probably say something
about the suggestion in the upcoming developer meeting. :)

PS: The documentation can also mention whether there are 
speed considerations, so I think this is another reason 
why speed considerations should not come primary as opposed
to functionality that may be useful (whether it is, I do not
know; just mentioning this in general).

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

* 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/

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:90728] [Ruby trunk Feature#6670] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (32 preceding siblings ...)
  2018-04-18 16:54 ` [ruby-core:86584] [Ruby trunk Feature#6670] " shevegen
@ 2018-12-26  8:24 ` mame
  2018-12-26 14:31 ` [ruby-core:90731] [Ruby trunk Feature#6670][Closed] " mame
  34 siblings, 0 replies; 36+ messages in thread
From: mame @ 2018-12-26  8:24 UTC (permalink / raw
  To: ruby-core

Issue #6670 has been updated by mame (Yusuke Endoh).

Assignee changed from matz (Yukihiro Matsumoto) to mame (Yusuke Endoh)

Sorry for long absent.  We discussed this ticket at DevelopersMeeting20180419Japan, and matz decided to withdraw the deprecation of "String#bytes with block" and friends.  I'll remove the deprecation warnings soon.

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

* Author: yhara (Yutaka HARA)
* Status: Assigned
* Priority: Normal
* Assignee: mame (Yusuke Endoh)
* 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/

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [ruby-core:90731] [Ruby trunk Feature#6670][Closed] str.chars.last should be possible
  2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
                   ` (33 preceding siblings ...)
  2018-12-26  8:24 ` [ruby-core:90728] " mame
@ 2018-12-26 14:31 ` mame
  34 siblings, 0 replies; 36+ messages in thread
From: mame @ 2018-12-26 14:31 UTC (permalink / raw
  To: ruby-core

Issue #6670 has been updated by mame (Yusuke Endoh).

Status changed from Assigned to Closed

I committed r66575.  I forgot to write the ticket number...

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

* Author: yhara (Yutaka HARA)
* Status: Closed
* Priority: Normal
* Assignee: mame (Yusuke Endoh)
* 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/

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2018-12-26 14:31 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-29 17:52 [ruby-core:45963] [ruby-trunk - Feature #6670][Open] str.chars.last should be possible yhara (Yutaka HARA)
2012-06-29 17:54 ` [ruby-core:45964] [ruby-trunk - Feature #6670] " yhara (Yutaka HARA)
2012-07-01 16:41 ` [ruby-core:46061] [ruby-trunk - Feature #6670][Assigned] " mame (Yusuke Endoh)
2012-07-01 17:59 ` [ruby-core:46077] [ruby-trunk - Feature #6670] " trans (Thomas Sawyer)
2012-07-02  3:07 ` [ruby-core:46097] " marcandre (Marc-Andre Lafortune)
2012-07-24 13:54 ` [ruby-core:46728] " mame (Yusuke Endoh)
2012-08-03 10:53 ` [ruby-core:46960] " yhara (Yutaka HARA)
2012-08-15 12:30 ` [ruby-core:47212] " yhara (Yutaka HARA)
2012-10-26 22:13 ` [ruby-core:48381] " ko1 (Koichi Sasada)
2012-10-29  8:43 ` [ruby-core:48540] " knu (Akinori MUSHA)
2012-11-19  2:59 ` [ruby-core:49551] " zzak (Zachary Scott)
2012-11-19 18:14 ` [ruby-core:49601] " mame (Yusuke Endoh)
2012-11-24  2:16 ` [ruby-core:49970] " mame (Yusuke Endoh)
2012-11-24 10:38 ` [ruby-core:50035] " knu (Akinori MUSHA)
2012-11-24 13:18 ` [ruby-core:50039] " nagachika (Tomoyuki Chikanaga)
2012-11-24 13:24 ` [ruby-core:50040] " mame (Yusuke Endoh)
2012-11-25 17:23 ` [ruby-core:50082] " brixen (Brian Ford)
2012-11-25 21:01 ` [ruby-core:50091] " drbrain (Eric Hodel)
2012-11-26 20:36 ` [ruby-core:50179] [ruby-trunk - Feature #6670][Assigned] " naruse (Yui NARUSE)
2012-11-26 23:15 ` [ruby-core:50184] [ruby-trunk - Feature #6670] " marcandre (Marc-Andre Lafortune)
2012-11-27  3:21 ` [ruby-core:50192] " mame (Yusuke Endoh)
2012-11-27 11:14 ` [ruby-core:50219] " knu (Akinori MUSHA)
2012-11-27 13:21 ` [ruby-core:50222] " trans (Thomas Sawyer)
2012-11-27 14:56 ` [ruby-core:50228] " knu (Akinori MUSHA)
2012-11-27 16:32 ` [ruby-core:50231] " yhara (Yutaka HARA)
2012-11-28  0:38 ` [ruby-core:50238] " duerst (Martin Dürst)
2012-11-28  3:20 ` [ruby-core:50241] " yhara (Yutaka HARA)
2012-11-29  5:13 ` [ruby-core:50298] " duerst (Martin Dürst)
2012-11-29  8:12 ` [ruby-core:50305] " knu (Akinori MUSHA)
2012-11-30  9:08 ` [ruby-core:50378] " yhara (Yutaka HARA)
2012-11-30 16:28 ` [ruby-core:50399] " drbrain (Eric Hodel)
2012-11-30 17:02 ` [ruby-core:50401] " yhara (Yutaka HARA)
2018-04-18  6:50 ` [ruby-core:86570] [Ruby trunk Feature#6670][Assigned] " mame
2018-04-18 16:54 ` [ruby-core:86584] [Ruby trunk Feature#6670] " shevegen
2018-12-26  8:24 ` [ruby-core:90728] " mame
2018-12-26 14:31 ` [ruby-core:90731] [Ruby trunk Feature#6670][Closed] " mame

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).