ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "drbrain (Eric Hodel)" <drbrain@segment7.net>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:46484] [ruby-trunk - Feature #6721] Object#yield_self
Date: Sun, 15 Jul 2012 09:08:51 +0900	[thread overview]
Message-ID: <redmine.journal-28124.20120715090851@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-6721.20120711163521@ruby-lang.org


Issue #6721 has been updated by drbrain (Eric Hodel).


Your current names are less clear than using a local variable.  Using a local variable reveals your intentions very clearly:  

  o = object.associated_object
  attr = o.attribute if o

It's obvious that attr is only set if the associated object exists.

For your second example there's just too much going on to clearly see what the intention is.  By first separating data gathering from creating of the mailing_address Hash things become much clearer:

  address = person[:address]
  street = address[:street] if address.is_a?(Hash)

  mailing_address = {
    :name   => person[:name],
    :street => street,
  }

As in the first example, your current names don't reveal what yield_self is supposed to do in a way that's clearer than using local variables for construction of mailing_address
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-28124

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
I think the following method is missing from Ruby:

 class Object
   def yield_self(*args)
     yield(self, *args)
   end
 end

I do not know a good use case, but it looks very natural to me.  It can be used in method chains.

What do you think?  Is there an alternative?
=end



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

  parent reply	other threads:[~2012-07-15  0:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-11  7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
2012-07-11  9:33 ` [ruby-core:46321] [ruby-trunk - Feature #6721] Object#yield_self jballanc (Joshua Ballanco)
2012-07-11 12:22 ` [ruby-core:46323] " alexeymuranov (Alexey Muranov)
2012-07-14 15:08 ` [ruby-core:46479] " alexeymuranov (Alexey Muranov)
2012-07-14 21:27 ` [ruby-core:46481] " nobu (Nobuyoshi Nakada)
2012-07-14 22:54 ` [ruby-core:46483] " alexeymuranov (Alexey Muranov)
2012-07-15  0:08 ` drbrain (Eric Hodel) [this message]
2012-07-15 20:10 ` [ruby-core:46498] " alexeymuranov (Alexey Muranov)
2012-08-06 21:15 ` [ruby-core:47027] " trans (Thomas Sawyer)
2012-10-27 15:18 ` [ruby-core:48490] " yhara (Yutaka HARA)
2012-11-10 10:19 ` [ruby-core:49192] " alexeymuranov (Alexey Muranov)
2012-11-18  3:20 ` [ruby-core:49508] " boris_stitnicky (Boris Stitnicky)
2012-11-24 17:28 ` [ruby-core:50047] " headius (Charles Nutter)
2013-02-08 13:41 ` [ruby-core:52035] " alexeymuranov (Alexey Muranov)
2013-02-08 20:11   ` [ruby-core:52044] " Alex aka Sinm
2013-02-09 11:42 ` [ruby-core:52070] " alexeymuranov (Alexey Muranov)
2013-02-18  0:21 ` [ruby-core:52423] " ko1 (Koichi Sasada)
2013-05-17  8:01 ` [ruby-core:55022] " aleph1 (Elias Levy)
2013-05-17  8:48   ` [ruby-core:55023] " Nobuyoshi Nakada
2013-05-17 16:32 ` [ruby-core:55029] " alexeymuranov (Alexey Muranov)
2013-05-17 20:41 ` [ruby-core:55032] " boris_stitnicky (Boris Stitnicky)
2013-05-18  8:21 ` [ruby-core:55047] " alexeymuranov (Alexey Muranov)
2013-08-31 20:32 ` [ruby-core:56950] " alexeymuranov (Alexey Muranov)
2013-09-29 11:04 ` [ruby-core:57465] " abinoam (Abinoam P. Marques Jr.)
2015-11-20 18:13 ` [ruby-core:71612] [Ruby trunk " nobu

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-28124.20120715090851@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).