From: sawadatsuyoshi@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:96654] [Ruby master Feature#9587] Integer#times with optional starting value
Date: Sat, 04 Jan 2020 17:28:22 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-83624.20200104172821.79c01d468ff2da40@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-9587.20140302195238@ruby-lang.org
Issue #9587 has been updated by sawa (Tsuyoshi Sawada).
I now think that writing as below is good enough:
```ruby
6.times.with_index(1){|_, i| puts "Chapter#{i}"}
```
I withdraw this proposal. Please close it.
----------------------------------------
Feature #9587: Integer#times with optional starting value
https://bugs.ruby-lang.org/issues/9587#change-83624
* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Just like `Enumerator#with_index` takes an optional argument that specifies the initial value of the index, I would like to request that `Integer#times` take an optional argument that specifies the initial value. The usefulness of it is similar to that of `with_index` taking an argument. We sometimes want to repeat tasks a given number of times, and want to use an index not necessarily starting from `0`.
6.times(1){|i| puts "Chapter #{i}"}
should give
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
with the return value `6`. We can do it with `1.upto(6)`, or with `#{i + 1}` within the block, but giving the initial value to `times` is much easier.
--
https://bugs.ruby-lang.org/
prev parent reply other threads:[~2020-01-04 17:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-9587.20140302195238@ruby-lang.org>
2014-03-02 19:52 ` [ruby-core:61233] [ruby-trunk - Feature #9587] [Open] Integer#times with optional starting value sawadatsuyoshi
2014-03-02 21:17 ` [ruby-core:61234] [ruby-trunk - Feature #9587] " ruby-core
2014-03-03 11:17 ` [ruby-core:61254] " sawadatsuyoshi
2014-03-03 12:24 ` [ruby-core:61256] " eregontp
2014-03-03 20:09 ` [ruby-core:61262] " Matthew Kerwin
2014-03-03 20:10 ` [ruby-core:61263] " matthew
2020-01-04 17:28 ` sawadatsuyoshi [this message]
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-83624.20200104172821.79c01d468ff2da40@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).