Bug #15428

Updated by zverok (Victor Shepelev) about 1 year ago

I believe, that solution of #6284 introduced `Proc#>>` and `Proc#<<`, but the requirements important language inconsistency: as far as I can tell, it insists that **anything that responds to the argument `#call`** is totally inconsistent with ANY other place in Ruby. composable, e.g. **quacks like `Proc`**. 

 Currently, The problem is, previously it is the **only** place in Ruby where coercing argument to `Proc` is done with was **never** this way. `#call` method. Everywhere else it is done with `#to_proc`, and `#call` method never had any special significance except for `.()` sugar. I believe there are two possible actions: 

 1. change `#>>` and `#<<` to use `#to_proc` (which will give Symbols composability for free), **or, alternatively** 
 2. state that `#call` from now on has a special meaning in Ruby and probably decide on other APIs that should respect nice shortcut of `.()`, but when you wanted to tell something can quack like proc, it (for example, auto-define **always** was done by defining `#to_proc` on any object that has `#call`) method. 

 Either is OK, the current situation is not. 

 PS: One more problem (that probably should I understand it could be discussed separately) too late to ask, but I wonder why this inconsistency was introduced and is that check for `#call` existence is performed pretty late, which can lead there a plan to take this kind of errors: 

 # At code loading time: 

 # I erroneously thought step further?  
 For me personally, this is correct. It is not, `#call`/`#to_proc` dichotomy was always weird and feels like it needs some unification (maybe anything having `#call` will automatically have `#to_proc` method?), but the line would perform without 
 # any error. 
 PROCESSOR = JSON.method(:parse) >> :symbolize_keys  

 # Later, in runtime: 
 '{"foo": "bar"}'.then(&PROCESSOR) 
 # NoMethodError (undefined method `call' situation when exactly one language feature treats it differently looks pretty weird for :symbolize_keys:Symbol) 

 **UPD 2018-12-29:** As this ticket was ignored prior to 2.6 release, I rewrote it in an "actionable" instead of "question" manner. me.