From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 0EF8A17D5F39 for ; Mon, 3 Mar 2014 20:23:12 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 1905DB5D83F for ; Mon, 3 Mar 2014 20:17:30 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 7362197A839 for ; Mon, 3 Mar 2014 20:17:32 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ntft0_ZyjQwZ for ; Mon, 3 Mar 2014 20:17:32 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 13F6897A832 for ; Mon, 3 Mar 2014 20:17:32 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 1A22395241B for ; Mon, 3 Mar 2014 20:17:26 +0900 (JST) Received: from [221.186.184.76] (unknown [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 9FBF6120604; Mon, 3 Mar 2014 20:17:17 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with SMTP id D473312033E for ; Mon, 3 Mar 2014 20:17:14 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=rIhETnTgXwikKNH/uvd4n/IELdk=; b=ixwexrmaEn5BDcbmPx +BrjhxYTZ3bdBV5YX1oBTLOLeAAXNrwQNy4D02YgVGxuBFT1H6GQ/8l/tHrvyNZ6 iPulsZQkpFklJisxQptukuXswOhtsBlvBVh7ls2GNOzXbVPq3erSOWJp3xsHgIph JFpe3MsNQ4kjLhe4eLfPD9rgI= Received: by mf165.sendgrid.net with SMTP id mf165.26017.531464B94 Mon, 03 Mar 2014 11:17:13 +0000 (UTC) Received: from herokuapp.com (ec2-54-211-42-6.compute-1.amazonaws.com [54.211.42.6]) by ismtpd-022 (SG) with ESMTP id 14487a97401.68ef.79c969 for ; Mon, 03 Mar 2014 11:17:13 +0000 (GMT) Date: Mon, 03 Mar 2014 11:17:13 +0000 From: sawadatsuyoshi@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 35078 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 9587 X-Redmine-Issue-Author: sawa X-Redmine-Sender: sawa X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: OOF Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS46QEdZJw7TMx/JbRnFW1nZjgu6WxslDtey4TS7OmtzWeZe9Kz58Pz4jW9DF+SfHgSCK1BrkLaW3HVQLlVyaw4haAFUs8TWKuazqEffyrVTOOJJccQMT+XfsP8yRSkqB4A= X-ML-Name: ruby-core X-Mail-Count: 61254 Subject: [ruby-core:61254] [ruby-trunk - Feature #9587] Integer#times with optional starting value X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #9587 has been updated by Tsuyoshi Sawada. Marc-Andre Lafortune wrote: > How exactly would it be easier than `1.upto(6)`? When the start value is `1`, the argument `6` of `upto` coincidentally matches what would be the receiver of `times`, and you may not see the benifit, but when it is some other value such as `5`, then you would need to calculate that in mind: 5.upto(11) # Need to calculate 11 (= 5 + 6) 6.times(5) # This is easier A use case maybe when you are writing labels for pagination buttons. You know the start value, say 17, and you want to display ten next pages. Then, 10.times(17){|i| ...} would give i = 17, 18, ..., 26. Doing this with `upto` or addition to the index within a `times` block may be a cause of careless bugs. ---------------------------------------- Feature #9587: Integer#times with optional starting value https://bugs.ruby-lang.org/issues/9587#change-45594 * Author: Tsuyoshi Sawada * Status: Open * Priority: Normal * Assignee: * Category: * 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. -- http://bugs.ruby-lang.org/