Project

General

Profile

Feature #13562

Use a sized enumerator with #yield_self

Added by shan (Shannon Skipper) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:81151]

Description

The #yield_self Enumerator instance always has a #count of 1. I think it might be nice to provide a lazy #size of 1 to match the #count for parity.

Currently:

42.yield_self.count #=> 1
42.yield_self.size #=> nil

I propose:

42.yield_self.count #=> 1
42.yield_self.size #=> 1

Associated revisions

Revision 58714
Added by nobu (Nobuyoshi Nakada) over 2 years ago

object.c: use a sized enumerator with #yield_self

  • object.c (rb_obj_size): The #yield_self Enumerator instance always has a #count of 1. This provides a lazy #size of 1 to match the count instead of nil. [Fix GH-1615]

Author: Shannon Skipper shannonskipper@gmail.com

History

Updated by shan (Shannon Skipper) over 2 years ago

I'm not at all sure about my implementation, but here is a pull request with my attempt: https://github.com/ruby/ruby/pull/1615

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

The patch seems okay to me, but honestly I don't see any practical use case of it. Do you nedd this?

Updated by Hanmac (Hans Mackowiak) over 2 years ago

shyouhei (Shyouhei Urabe) wrote:

The patch seems okay to me, but honestly I don't see any practical use case of it. Do you nedd this?

the pr was already merged, but this ticket was not closed because of that

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

Hanmac (Hans Mackowiak) wrote:

shyouhei (Shyouhei Urabe) wrote:

The patch seems okay to me, but honestly I don't see any practical use case of it. Do you nedd this?

the pr was already merged, but this ticket was not closed because of that

Thank you. Issue updated to refer the changeset.

#5

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF