[#97536] [Ruby master Bug#16694] JIT vs hardened GCC with PCH — v.ondruch@...
Issue #16694 has been reported by vo.x (Vit Ondruch).
11 messages
2020/03/18
[ruby-core:97342] [Ruby master Feature#16667] Allow parameters to Symbol#to_proc and Method#to_proc
From:
hanmac@...
Date:
2020-03-03 14:27:15 UTC
List:
ruby-core #97342
Issue #16667 has been updated by Hanmac (Hans Mackowiak).
@jgomo3 i found my old Symbol#call code
~~~ ruby
class Symbol
class SymbolHelper
def initialize(obj,methId,*args)
@obj= obj
@args=args
@methId=methId
end
def method_missing(methId,*args)
return SymbolHelper.new(self,methId,*args)
end
def to_proc
proc {|obj| (@obj.nil? ? obj : @obj.to_proc.(obj)).public_send(@methId,*@args) }
end
end
def call(*args)
return SymbolHelper.new(nil,self,*args)
end
end
~~~
you can chain it like that
~~~ ruby
[1,2,3,4].map(&:to_s.(2)) #=> ["1", "10", "11", "100"]
[1,2,3,4].map(&:to_s.(2).length) #=> [1, 2, 2, 3]
~~~
might be updated for keyword arguments
----------------------------------------
Feature #16667: Allow parameters to Symbol#to_proc and Method#to_proc
https://bugs.ruby-lang.org/issues/16667#change-84463
* Author: jgomo3 (Jes俍 Gez)
* Status: Open
* Priority: Normal
----------------------------------------
Allow parameters to Symbol#to_proc and Method#to_proc
So we can say:
``` ruby
ary.map(:dig.to_proc(:id))
```
Instead of
``` ruby
ary.map { |e| e.dig(:id) }
```
Oppening the posibilities to refine the `&` operator in the future, for something like:
``` ruby
ary.map(&(:dig, :id))
```
Related:
* https://bugs.ruby-lang.org/issues/11161
* https://bugs.ruby-lang.org/issues/16435
--
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>