[#74190] [Ruby trunk Feature#12134] Comparison between `true` and `false` — duerst@...
Issue #12134 has been updated by Martin D端rst.
3 messages
2016/03/07
[#74269] Type systems for Ruby — Rob Blanco <ml@...>
Dear ruby-core,
5 messages
2016/03/10
[#74395] [Ruby trunk Feature#12142] Hash tables with open addressing — shyouhei@...
Issue #12142 has been updated by Shyouhei Urabe.
3 messages
2016/03/17
[ruby-core:74079] [Ruby trunk Feature#12115] Add Symbol#call to allow to_proc shorthand with arguments
From:
sawadatsuyoshi@...
Date:
2016-03-01 06:15:19 UTC
List:
ruby-core #74079
Issue #12115 has been updated by Tsuyoshi Sawada.
For a similar proposal, please cf. #10394.
----------------------------------------
Feature #12115: Add Symbol#call to allow to_proc shorthand with arguments
https://bugs.ruby-lang.org/issues/12115#change-57230
* Author: Felix B端nemann
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
I am a great fan of the `Symbol#to_proc` shorthand when mapping or reducing collections:
```ruby
[1,2,16].map(&:to_s)
=> ["1", "2", "16"]
[1,2,16].reduce(&:*)
=> 32
```
I often wish it would be possible to pass an argument to the method when doing this, which currently requires a block and is more verbose:
```ruby
[1,2,16].map { |n| n.to_s(16) }
=> ["1", "2", "10"]
# active_support example
{id: 1, parent_id: nil}.as_json.transform_keys { |k| k.camelize :lower }.to_json
=> '{"id":1,"parentId":null}'
```
It would be much shorter, if ruby allowed this:
```ruby
[1,2,16].map(&:to_s.(16))
=> ["1", "2", "10"]
# active_support example
{id: 1, parent_id: nil}.as_json.transform_keys(&:camelize.(:lower)).to_json
=> '{"id":1,"parentId":null}'
```
This can be implemented easily, by adding the `Symbol#call` method:
```ruby
class Symbol
def call(*args, &block)
->(caller, *rest) { caller.send(self, *rest, *args, &block) }
end
end
```
*Source*: [stackoverflow: Can you supply arguments to the map(&:method) syntax in Ruby?](http://stackoverflow.com/questions/23695653/can-you-supply-arguments-to-the-mapmethod-syntax-in-ruby)
**I think this is a rather common use case, so I propose to add `Symbol#call` to the Ruby standard library.**
--
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>