ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: eregontp@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:100187] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects
Date: Sun, 27 Sep 2020 10:05:13 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-87758.20200927100513.772@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17195.20200926132038.772@ruby-lang.org

Issue #17195 has been updated by Eregon (Benoit Daloze).


I just realized, this is problematic because `Enumerator::ArithmeticSequence` is a subclass of `Enumerator` and not of `Range`.
If it was a subclass of Range then I think it would be fine to freeze it.

But since it subclasses Enumerator, it has mutably methods like `Enumerator#next`:
```ruby
[7] pry(main)> enum = (1..5).step(2)
=> ((1..5).step(2))
[8] pry(main)> enum.next
=> 1
[9] pry(main)> enum.next
=> 3
[10] pry(main)> enum.next
=> 5
[11] pry(main)> enum.next
StopIteration: iteration reached an end
from (pry):11:in `next'
```

@mrkn do you remember why ArithmeticSequence is an Enumerator subclass and not a Range subclass?

----------------------------------------
Feature #17195: Freeze Enumerator::ArithmeticSequence objects
https://bugs.ruby-lang.org/issues/17195#change-87758

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
----------------------------------------
Now, all Ranges are frozen (#15504).

Enumerator::ArithmeticSequence is very similar to Range, just with an extra `step`.
They're essentially already immutable, except that one could use set instance variables, but it seems of little use.

So, should we make Enumerator::ArithmeticSequence frozen too?



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

  parent reply	other threads:[~2020-09-27 10:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-26 13:20 [ruby-core:100174] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects eregontp
2020-09-26 18:44 ` [ruby-core:100179] " marcandre-ruby-core
2020-09-27 10:05 ` eregontp [this message]
2020-10-09  8:01 ` [ruby-core:100346] " muraken
2020-10-09 18:15 ` [ruby-core:100350] " eregontp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-87758.20200927100513.772@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).