From: sean.m.huber@... Date: 2018-12-09T22:19:39+00:00 Subject: [ruby-core:90385] [CommonRuby Feature#13581] Syntax sugar for method reference Issue #13581 has been updated by shuber (Sean Huber). > matz (Yukihiro Matsumoto) wrote: >> Out of [ruby-core:85038](https://bugs.ruby-lang.org/issues/13581#change-69758) candidates, `.:` looks best to me (followed by `:::`). >> Let me consider it for a while. >> >> Matz. @matz and @nobu What do you guys think about this alternative syntax? (working proof of concept: https://github.com/LendingHome/pipe_operator) -9.pipe { abs | Math.sqrt | to_i } #=> 3 [9, 64].map(&Math.|.sqrt.to_i.to_s) #=> ["3", "8"] "https://api.github.com/repos/ruby/ruby".| do URI.parse Net::HTTP.get JSON.parse.fetch("stargazers_count") yield_self { |n| "Ruby has #{n} stars" } Kernel.puts end #=> Ruby has 15120 stars There's nothing really new/special here - it's just a block of expressions like any other Ruby DSL and the pipe | operator has been around for decades! The https://github.com/LendingHome/pipe_operator README contains many more examples and the implementation details - I would love to hear your thoughts! Thanks, Sean Huber ---------------------------------------- Feature #13581: Syntax sugar for method reference https://bugs.ruby-lang.org/issues/13581#change-75505 * Author: americodls (Americo Duarte) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Some another programming languages (even Java, in version 8) has a cool way to refer a method as a reference. I wrote some examples here: https://gist.github.com/americodls/20981b2864d166eee8d231904303f24b I miss this thing in ruby. I would thinking if is possible some like this: ~~~ roots = [1, 4, 9].map &Math.method(:sqrt) ~~~ Could be like this: ~~~ roots = [1, 4, 9].map Math->method ~~~ What do you guys thinking about it? -- https://bugs.ruby-lang.org/ Unsubscribe: