[#111712] [Ruby master Feature#19322] Support spawning "private" child processes — "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" <ruby-core@...>
SXNzdWUgIzE5MzIyIGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGtqdHNhbmFrdHNpZGlzIChLSiBUc2Fu
14 messages
2023/01/07
[ruby-core:111861] [Ruby master Feature#8827] A method that flips the receiver and the first argument
From:
"sawa (Tsuyoshi Sawada) via ruby-core" <ruby-core@...>
Date:
2023-01-17 18:32:25 UTC
List:
ruby-core #111861
Issue #8827 has been updated by sawa (Tsuyoshi Sawada).
Since `then` has been introduced, I think using that is more straightforward. I withdraw this feature. Please close it.
----------------------------------------
Feature #8827: A method that flips the receiver and the first argument
https://bugs.ruby-lang.org/issues/8827#change-101274
* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
----------------------------------------
=begin
If it often happens that we need to pass to a method an argument that is the result of a long chain of operations:
Hash[some_chain_of_operations_that_ends_up_with_an_array]
File.read(some_chain_of_operations_that_ends_up_with_a_string)
YAML.dump(some_chain_of_operations_that_ends_up_with_an_object)
...
I believe one basic tenet of Ruby is to encourage method chaining, but that practice is discouraged in the examples above. It would be convenient if there is a method (let us call this `Object#flip`) that flips the receiver and the first argument and sends the method so that the examples above can be written as follows:
some_chain_of_operations_that_ends_up_with_an_array.flip(Hash, :[])
some_chain_of_operations_that_ends_up_with_a_string.flip(File, :read)
some_chain_of_operations_that_ends_up_with_an_object.flip(YAML, :dump)
...
The implementation in Ruby may be as follows:
class Object
def flip receiver, method, *rest, &pr
receiver.send(method, self, *rest, &pr)
end
end
It would be good if we can have that as a built-in Ruby method.
=end
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/