* [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self
@ 2012-07-11 7:35 alexeymuranov (Alexey Muranov)
2012-07-11 9:33 ` [ruby-core:46321] [ruby-trunk - Feature #6721] Object#yield_self jballanc (Joshua Ballanco)
` (21 more replies)
0 siblings, 22 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-07-11 7:35 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been reported by alexeymuranov (Alexey Muranov).
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721
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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:46321] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
@ 2012-07-11 9:33 ` jballanc (Joshua Ballanco)
2012-07-11 12:22 ` [ruby-core:46323] " alexeymuranov (Alexey Muranov)
` (20 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: jballanc (Joshua Ballanco) @ 2012-07-11 9:33 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by jballanc (Joshua Ballanco).
How is this significantly different than Object#tap?
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-27938
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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:46323] [ruby-trunk - Feature #6721] Object#yield_self
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 ` alexeymuranov (Alexey Muranov)
2012-07-14 15:08 ` [ruby-core:46479] " alexeymuranov (Alexey Muranov)
` (19 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-07-11 12:22 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
=begin
jballanc (Joshua Ballanco) wrote:
> How is this significantly different than Object#tap?
It executes the block and returns its output. For example:
puts "2*2 = #{ 2.yield_self { |x| x*x } }"
=end
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-27939
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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:46479] [ruby-trunk - Feature #6721] Object#yield_self
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 ` alexeymuranov (Alexey Muranov)
2012-07-14 21:27 ` [ruby-core:46481] " nobu (Nobuyoshi Nakada)
` (18 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-07-14 15:08 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
=begin
I've come up with some use case for illustration. I have also looked into the Ruby on Rails (({Object#try})) method because it can serve a similar purpose. I think (({yield_self})) is more basic than (({try})).
Here are two examples of a use case:
attr = object.associated_object.yield_self { |o| o.nil? ? nil : o.attribute }
mailing_address = { :name => person[:name],
:street => person[:address].yield_self { |a| a.is_a?(Hash) ? a[:street] : nil }
}
Here is for comparison the implementation of (({Object#try})) in Ruby on Rails:
def try(*a, &b)
if a.empty? && block_given?
yield self
else
__send__(*a, &b)
end
end
=end
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-28120
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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:46481] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (2 preceding siblings ...)
2012-07-14 15:08 ` [ruby-core:46479] " alexeymuranov (Alexey Muranov)
@ 2012-07-14 21:27 ` nobu (Nobuyoshi Nakada)
2012-07-14 22:54 ` [ruby-core:46483] " alexeymuranov (Alexey Muranov)
` (17 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2012-07-14 21:27 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by nobu (Nobuyoshi Nakada).
I'm not against the feature itself, but don't like the name.
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-28122
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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:46483] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (3 preceding siblings ...)
2012-07-14 21:27 ` [ruby-core:46481] " nobu (Nobuyoshi Nakada)
@ 2012-07-14 22:54 ` alexeymuranov (Alexey Muranov)
2012-07-15 0:08 ` [ruby-core:46484] " drbrain (Eric Hodel)
` (16 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-07-14 22:54 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
nobu (Nobuyoshi Nakada) wrote:
> I'm not against the feature itself, but don't like the name.
#yield_to, #submit_to, #surrender, #capitulate ? :)
Or otherwise, #apply:
2.apply { |x| x*x } # => 4
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-28123
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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:46484] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (4 preceding siblings ...)
2012-07-14 22:54 ` [ruby-core:46483] " alexeymuranov (Alexey Muranov)
@ 2012-07-15 0:08 ` drbrain (Eric Hodel)
2012-07-15 20:10 ` [ruby-core:46498] " alexeymuranov (Alexey Muranov)
` (15 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: drbrain (Eric Hodel) @ 2012-07-15 0:08 UTC (permalink / raw)
To: ruby-core
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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:46498] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (5 preceding siblings ...)
2012-07-15 0:08 ` [ruby-core:46484] " drbrain (Eric Hodel)
@ 2012-07-15 20:10 ` alexeymuranov (Alexey Muranov)
2012-08-06 21:15 ` [ruby-core:47027] " trans (Thomas Sawyer)
` (14 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-07-15 20:10 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
drbrain (Eric Hodel) wrote:
> Your current names are less clear than using a local variable. Using a local variable reveals your intentions very clearly:
Well, using method chains with blocks is always less clear than using local variables.
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-28134
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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:47027] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (6 preceding siblings ...)
2012-07-15 20:10 ` [ruby-core:46498] " alexeymuranov (Alexey Muranov)
@ 2012-08-06 21:15 ` trans (Thomas Sawyer)
2012-10-27 15:18 ` [ruby-core:48490] " yhara (Yutaka HARA)
` (13 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: trans (Thomas Sawyer) @ 2012-08-06 21:15 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by trans (Thomas Sawyer).
This is basically #ergo in Ruby Facets. Essentially:
def ergo
return yield(self) if block_given?
self
end
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-28686
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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:48490] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (7 preceding siblings ...)
2012-08-06 21:15 ` [ruby-core:47027] " trans (Thomas Sawyer)
@ 2012-10-27 15:18 ` yhara (Yutaka HARA)
2012-11-10 10:19 ` [ruby-core:49192] " alexeymuranov (Alexey Muranov)
` (12 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: yhara (Yutaka HARA) @ 2012-10-27 15:18 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by yhara (Yutaka HARA).
Category set to core
Target version set to next minor
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-31821
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:49192] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (8 preceding siblings ...)
2012-10-27 15:18 ` [ruby-core:48490] " yhara (Yutaka HARA)
@ 2012-11-10 10:19 ` alexeymuranov (Alexey Muranov)
2012-11-18 3:20 ` [ruby-core:49508] " boris_stitnicky (Boris Stitnicky)
` (11 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-11-10 10:19 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
=begin
After commenting on #6284, i have a new proposition for this method's name: (({Object#^})). Also, i suggest to allow it to take a block, a proc, a lambda, or a symbol. I think this will not conflict with existing uses of #^, however the classes that implement it for certain argument types should not forget to call (({super})) if the argument type is not recognized by them.
For example:
# Formatting a string:
format_as_title = lambda { |str| "Title: #{ str.strip.capitalize }" }
title = " something to be a title " ^ format_as_title # instead of `format_as_title.call(" something to be a title ")`
# Squareing the 2:
four = 2 ^ { |x| x*x } # instead of `four = 2^[**2`
# Converting a string to an integer:
five = "5" ^ :to_i # instead of `five = "5".to_i`
This is consistent with a rare mathematical notation for function application: sometimes instead of "f(x)", the "exponential" notation "x^f" is used.
This would also open a door to compose lambdas from left to right, if the majority decides so (this is being discussed in #6284)
=end
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-32742
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:49508] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (9 preceding siblings ...)
2012-11-10 10:19 ` [ruby-core:49192] " alexeymuranov (Alexey Muranov)
@ 2012-11-18 3:20 ` boris_stitnicky (Boris Stitnicky)
2012-11-24 17:28 ` [ruby-core:50047] " headius (Charles Nutter)
` (10 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: boris_stitnicky (Boris Stitnicky) @ 2012-11-18 3:20 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by boris_stitnicky (Boris Stitnicky).
#ergo is a well-thought method name, I like it better than all others.
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-33040
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:50047] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (10 preceding siblings ...)
2012-11-18 3:20 ` [ruby-core:49508] " boris_stitnicky (Boris Stitnicky)
@ 2012-11-24 17:28 ` headius (Charles Nutter)
2013-02-08 13:41 ` [ruby-core:52035] " alexeymuranov (Alexey Muranov)
` (9 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: headius (Charles Nutter) @ 2012-11-24 17:28 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by headius (Charles Nutter).
It occurs to me #apply is used in some other languages to refer to the elements of a collection rather than to the collection itself.
[1,2,3].apply {|n| puts n}
Did we ever decide if the #self method would be added? If it were, it would be simple to have it take a block:
four = 2.self {|n| n * n}
That would make #self basically be #ergo as defined by Facets.
Worth noting that you can get nearly as concise syntax today, albeit in reverse order:
four = ->{|n| n * n}.(2)
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-33823
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:52035] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (11 preceding siblings ...)
2012-11-24 17:28 ` [ruby-core:50047] " headius (Charles Nutter)
@ 2013-02-08 13:41 ` 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)
` (8 subsequent siblings)
21 siblings, 1 reply; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2013-02-08 13:41 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
=begin
Here is a "real life" use case. It again has to do with formatting strings.
I want to have a list of conference participants in the form:
Full Name (Affiliation, academic position)
but without empty parentheses or trailing comma if the person has not
profided the affiliation or the position. So i did like this:
class Participant
def full_name_with_affiliation_and_position
full_name +
lambda { |a_ap| a_ap.empty? ? '' : " (#{ a_ap })" }[[affiliation, academic_position].compact.join(', ')]
end
end
(I will appreciate any more elegant solution.)
With (({#yield_self})) (or any other name for it), i would have written:
class Participant
def full_name_with_affiliation_and_position
full_name +
[affiliation, academic_position].compact.join(', ')].yield_self { |a_ap| a_ap.empty? ? '' : " (#{ a_ap })" }
end
end
This would be a bit more readable for me.
=end
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-36056
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:52044] Re: [ruby-trunk - Feature #6721] Object#yield_self
2013-02-08 13:41 ` [ruby-core:52035] " alexeymuranov (Alexey Muranov)
@ 2013-02-08 20:11 ` Alex aka Sinm
0 siblings, 0 replies; 25+ messages in thread
From: Alex aka Sinm @ 2013-02-08 20:11 UTC (permalink / raw)
To: ruby-core
[-- Attachment #1: Type: text/plain, Size: 2023 bytes --]
Why you can't simply do the following?
def full_name_with_affiliation_and_position
a_ap = " (#{a_ap})" unless (a_ap = [affiliation, academic_position].compact.join ', ').empty?
"#{full_name}#{a_ap}"
end
On Friday, 8 February 2013 г. at 17:41, alexeymuranov (Alexey Muranov) wrote:
>
> Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
>
>
> =begin
> Here is a "real life" use case. It again has to do with formatting strings.
>
> I want to have a list of conference participants in the form:
> Full Name (Affiliation, academic position)
> but without empty parentheses or trailing comma if the person has not
> profided the affiliation or the position. So i did like this:
>
> class Participant
> def full_name_with_affiliation_and_position
> full_name +
> lambda { |a_ap| a_ap.empty? ? '' : " (#{ a_ap })" }[[affiliation, academic_position].compact.join(', ')]
> end
> end
>
> (I will appreciate any more elegant solution.)
>
> With (({#yield_self})) (or any other name for it), i would have written:
>
> class Participant
> def full_name_with_affiliation_and_position
> full_name +
> [affiliation, academic_position].compact.join(', ')].yield_self { |a_ap| a_ap.empty? ? '' : " (#{ a_ap })" }
> end
> end
>
> This would be a bit more readable for me.
> =end
>
> ----------------------------------------
> Feature #6721: Object#yield_self
> https://bugs.ruby-lang.org/issues/6721#change-36056
>
> Author: alexeymuranov (Alexey Muranov)
> Status: Open
> Priority: Normal
> Assignee:
> Category: core
> Target version: next minor
>
>
> =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/
>
>
[-- Attachment #2: Type: text/html, Size: 3330 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:52070] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (12 preceding siblings ...)
2013-02-08 13:41 ` [ruby-core:52035] " alexeymuranov (Alexey Muranov)
@ 2013-02-09 11:42 ` alexeymuranov (Alexey Muranov)
2013-02-18 0:21 ` [ruby-core:52423] " ko1 (Koichi Sasada)
` (7 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2013-02-09 11:42 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
Anonymous wrote:
> Why you can't simply do the following?
>
> def full_name_with_affiliation_and_position
> a_ap = " (#{a_ap})" unless (a_ap = [affiliation, academic_position].compact.join ', ').empty?
> "#{full_name}#{a_ap}"
>
>
> end
I can, but i guess i want it to look more like declarative programming, than like imperative.
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-36088
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:52423] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (13 preceding siblings ...)
2013-02-09 11:42 ` [ruby-core:52070] " alexeymuranov (Alexey Muranov)
@ 2013-02-18 0:21 ` ko1 (Koichi Sasada)
2013-05-17 8:01 ` [ruby-core:55022] " aleph1 (Elias Levy)
` (6 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: ko1 (Koichi Sasada) @ 2013-02-18 0:21 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by ko1 (Koichi Sasada).
Assignee set to matz (Yukihiro Matsumoto)
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-36478
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:55022] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (14 preceding siblings ...)
2013-02-18 0:21 ` [ruby-core:52423] " ko1 (Koichi Sasada)
@ 2013-05-17 8:01 ` aleph1 (Elias Levy)
2013-05-17 8:48 ` [ruby-core:55023] " Nobuyoshi Nakada
2013-05-17 16:32 ` [ruby-core:55029] " alexeymuranov (Alexey Muranov)
` (5 subsequent siblings)
21 siblings, 1 reply; 25+ messages in thread
From: aleph1 (Elias Levy) @ 2013-05-17 8:01 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by aleph1 (Elias Levy).
nobu (Nobuyoshi Nakada) wrote:
> I'm not against the feature itself, but don't like the name.
At its core this feature relates to method chaining and transforming the object, something that cannot be done with Object#tap.
Some suggested names then: transform, alter, mutate, map, morph.
map may be the best choice, as its already used in enumerables and this is a natural equivalent for single objects. That said, it may lead to unnoticed bugs if someone thinks they are applying a map operation on an enumerable but for some reason they do so against some other object. So maybe one of the other names is better to ensure such cases fail.
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-39369
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:55023] Re: [ruby-trunk - Feature #6721] Object#yield_self
2013-05-17 8:01 ` [ruby-core:55022] " aleph1 (Elias Levy)
@ 2013-05-17 8:48 ` Nobuyoshi Nakada
0 siblings, 0 replies; 25+ messages in thread
From: Nobuyoshi Nakada @ 2013-05-17 8:48 UTC (permalink / raw)
To: ruby-core
(13/05/17 17:01), aleph1 (Elias Levy) wrote:
> map may be the best choice, as its already used in enumerables and this is a natural equivalent for single objects. That said, it may lead to unnoticed bugs if someone thinks they are applying a map operation on an enumerable but for some reason they do so against some other object. So maybe one of the other names is better to ensure such cases fail.
If it were Kernel#map, which would you expect by `{foo: 42}.map {...}` ?
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:55029] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (15 preceding siblings ...)
2013-05-17 8:01 ` [ruby-core:55022] " aleph1 (Elias Levy)
@ 2013-05-17 16:32 ` alexeymuranov (Alexey Muranov)
2013-05-17 20:41 ` [ruby-core:55032] " boris_stitnicky (Boris Stitnicky)
` (4 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2013-05-17 16:32 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
aleph1 (Elias Levy) wrote:
> nobu (Nobuyoshi Nakada) wrote:
> > I'm not against the feature itself, but don't like the name.
>
> At its core this feature relates to method chaining and transforming the object, something that cannot be done with Object#tap.
I do not agree: it simply yield self to a proc. It is more like a counterpart to `public_send`. I will try to see if Haskel has it, and what's the name, or i will think if it corresponds well to some mathematical operation.
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-39375
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:55032] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (16 preceding siblings ...)
2013-05-17 16:32 ` [ruby-core:55029] " alexeymuranov (Alexey Muranov)
@ 2013-05-17 20:41 ` boris_stitnicky (Boris Stitnicky)
2013-05-18 8:21 ` [ruby-core:55047] " alexeymuranov (Alexey Muranov)
` (3 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: boris_stitnicky (Boris Stitnicky) @ 2013-05-17 20:41 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by boris_stitnicky (Boris Stitnicky).
nobu (Nobuyoshi Nakada) wrote:
> I'm not against the feature itself, but don't like the name.
+1 to this opinion
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-39386
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:55047] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (17 preceding siblings ...)
2013-05-17 20:41 ` [ruby-core:55032] " boris_stitnicky (Boris Stitnicky)
@ 2013-05-18 8:21 ` alexeymuranov (Alexey Muranov)
2013-08-31 20:32 ` [ruby-core:56950] " alexeymuranov (Alexey Muranov)
` (2 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2013-05-18 8:21 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
=begin
It seems that Haskell does not have it: http://stackoverflow.com/questions/4090168/is-there-an-inverse-of-the-haskell-operator
I have found that in the context of Church numerals in lambda calculus, the expression (({λm.λn.nm})) is called (({exp})): http://en.wikipedia.org/wiki/Church_encoding#Computation_with_Church_numerals .
One more reason to use the (({^})) operator as i have suggested :).
This operation also would roughly correspond to (({apply})) in Scheme with reverse order of arguments. If i understand correctly, the (({apply})) in Scheme roughly correspond to (({call})) in Ruby, so maybe (({reverse_call}))?
=end
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-39418
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:56950] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (18 preceding siblings ...)
2013-05-18 8:21 ` [ruby-core:55047] " alexeymuranov (Alexey Muranov)
@ 2013-08-31 20:32 ` 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
21 siblings, 0 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2013-08-31 20:32 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
=begin
Another idea for the name: (({Object#cast})), by analogy with typecasting or cast iron. Iron (an object) is poured into a mold (a proc or a block).
class Object
def cast(*args, &block)
if block.nil?
p = args.shift
if p.is_a?(Proc)
p[self, *args]
else
raise 'The first argument of Object#cast should be a Proc, unless a block form is used.'
end
else
if args.empty?
block[self]
else
raise 'Object#cast does not accept arguments together with a block.'
end
end
end
end
2.cast {|x| x**3 } # => 8
p = proc {|x, y| x**y }
2.cast(p, 4) # => 16
=end
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-41509
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:57465] [ruby-trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (19 preceding siblings ...)
2013-08-31 20:32 ` [ruby-core:56950] " alexeymuranov (Alexey Muranov)
@ 2013-09-29 11:04 ` abinoam (Abinoam P. Marques Jr.)
2015-11-20 18:13 ` [ruby-core:71612] [Ruby trunk " nobu
21 siblings, 0 replies; 25+ messages in thread
From: abinoam (Abinoam P. Marques Jr.) @ 2013-09-29 11:04 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by abinoam (Abinoam P. Marques Jr.).
=begin
May I give a name suggestion?
Does "tap!" make sense in english?
(({2.tap {|x| x*2 }})) ((|# => 2|))
(({2.tap! {|x| x*2 }})) ((|# => 4|))
The exclamation mark alerts that the return value is being changed.
=end
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-42080
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor
=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/
^ permalink raw reply [flat|nested] 25+ messages in thread
* [ruby-core:71612] [Ruby trunk - Feature #6721] Object#yield_self
2012-07-11 7:35 [ruby-core:46320] [ruby-trunk - Feature #6721][Open] Object#yield_self alexeymuranov (Alexey Muranov)
` (20 preceding siblings ...)
2013-09-29 11:04 ` [ruby-core:57465] " abinoam (Abinoam P. Marques Jr.)
@ 2015-11-20 18:13 ` nobu
21 siblings, 0 replies; 25+ messages in thread
From: nobu @ 2015-11-20 18:13 UTC (permalink / raw)
To: ruby-core
Issue #6721 has been updated by Nobuyoshi Nakada.
Description updated
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-55009
* Author: Alexey Muranov
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I think the following method is missing from Ruby:
~~~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?
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2015-11-23 23:54 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [ruby-core:46484] " drbrain (Eric Hodel)
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
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).