ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Ale Miralles <amiralles.net@gmail.com>
To: Ruby developers <ruby-core@ruby-lang.org>
Subject: [ruby-core:91470] Re: [Ruby trunk Feature#4475] default variable name for parameter
Date: Thu, 7 Feb 2019 09:48:26 -0300	[thread overview]
Message-ID: <CALbVz+9yh8qi0a1TXFAty79rbbNRMmjUHRy_vnub2K9kut0XPQ@mail.gmail.com> (raw)
In-Reply-To: <redmine.journal-76718.20190207073556.7c6f8197c569167e@ruby-lang.org>


[-- Attachment #1.1: Type: text/plain, Size: 2099 bytes --]

Kotlin has it, too. It's a nice feature. In a pet language of mine, I added
the index as an "implicit" argument, too. Something like this:

elements  = ["foo", "bar", "baz"]
elements.each {
  puts "Element at index #{idx} has value #{it}."
}

"Element at index 0 has value foo."
"Element at index 1 has value bar."
etc....

I think it would be handy to have that in Ruby.

~ Ale Miralles.
http://amiralles.com.ar



On Thu, Feb 7, 2019 at 4:36 AM <matz@ruby-lang.org> wrote:

> Issue #4475 has been updated by matz (Yukihiro Matsumoto).
>
>
> I still feel weird when I see `@` and `@1` etc. Maybe I will get used to
> it after a while.
> I need time.
>
> Matz.
>
>
> ----------------------------------------
> Feature #4475: default variable name for parameter
> https://bugs.ruby-lang.org/issues/4475#change-76718
>
> * Author: jordi (jordi polo)
> * Status: Assigned
> * Priority: Normal
> * Assignee: matz (Yukihiro Matsumoto)
> * Target version:
> ----------------------------------------
> =begin
>
> There is a very common pattern in Ruby:
>
>  object.method do |variable_name|
>   variable_name doing something
>  end
>
>  Many times in fact the name of the object is so self explanatory that we
> don't care about the name of the variable of the block. It is common to see
> things like :
>
>  @my_sons.each { |s| s.sell_to_someone }
>
> or
>
>  Account.all.each { |a|  my_account << a.money }
>
>
>  People tend to choose s or a because we have the class or the object name
> just there to remind you about the context.
>
>
> I would like to know if can be a good idea to have a default name for that
> parameter. I think it is Groovy that does something like:
>
>   Account.all.each { my_account << it.money }
>
> Where it is automagically filled and it doesn't need to be declared.
>
> I think it is as readable or more (for newbies who don't know what is ||)
> and we save some typing :)
>
>
> =end
>
>
>
>
> --
> https://bugs.ruby-lang.org/
>
> Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
>

[-- Attachment #1.2: Type: text/html, Size: 3305 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2019-02-07 12:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-4475.20110306224849@ruby-lang.org>
2012-03-18 10:05 ` [ruby-core:43439] [ruby-trunk - Feature #4475][Assigned] default variable name for parameter nahi
2012-11-20 12:26 ` [ruby-core:49705] [ruby-trunk - Feature #4475] " mame (Yusuke Endoh)
2018-04-19  7:51 ` [ruby-core:86598] [Ruby trunk Feature#4475] " knu
2018-04-19 11:42 ` [ruby-core:86607] " matz
2018-09-13  5:44 ` [ruby-core:88969] " niinikazuki
2018-11-06 14:15 ` [ruby-core:89723] " shevegen
2018-11-06 14:33 ` [ruby-core:89724] " hanmac
2019-01-19  5:58 ` [ruby-core:91171] " merch-redmine
2019-02-07  7:35 ` [ruby-core:91458] " matz
2019-02-07 12:48   ` Ale Miralles [this message]
2019-02-07 12:55     ` [ruby-core:91471] " Ale Miralles
2019-02-08 16:35 ` [ruby-core:91497] " janfri26
2019-02-08 16:55 ` [ruby-core:91498] " merch-redmine
2019-03-11  4:47 ` [ruby-core:91743] " matz
2019-03-11 14:36 ` [ruby-core:91785] " nobu
2019-03-18 11:42 ` [ruby-core:91865] " shevegen
2019-03-18 15:43 ` [ruby-core:91868] " richard.schneeman+ruby-lang
2019-03-18 17:12 ` [ruby-core:91870] " bozhidar
2019-03-18 22:48 ` [ruby-core:91878] " gray.kemmey
2019-03-22  0:19 ` [ruby-core:91919] " harlemsquirrel
2019-03-22  0:31 ` [ruby-core:91920] " duerst
2019-03-22  6:56 ` [ruby-core:91923] " pascal.betz
2019-03-22 13:11 ` [ruby-core:91932] " mail

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=CALbVz+9yh8qi0a1TXFAty79rbbNRMmjUHRy_vnub2K9kut0XPQ@mail.gmail.com \
    --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).