Feature #6672
Updated by nobu (Nobuyoshi Nakada) over 12 years ago
=begin It looks odd to call Proc/Method `(({pr}))` `pr` using `(({pr.(*args)}))` `pr.(*args)` or `(({pr[*args]}))` `pr[*args]` syntax. Why not to use (({pr(*args)})) pr(*args) syntax? In such a case methods(procs) would become nearer to first-class object and calls are more standardized such that there's much less difference between method call and call of (({#call})) #call method So I suggest syntax `(({x.(*args,&block)}))` `x.(*args,&block)` alias to `(({x(*args,&block)}))` `x(*args,&block)` It will make it possible to transparently redefine any method in a scope like this: class String def my_meth(direction) index = method :rindex if direction == 'RtoL' # ... lots of code that uses #index method end def my_second_meth upcase = method :downcase # we decided to try what if we change all upcases to downcases in this method and added such a line # lots of code using upcase() method upcase() # it's sad that it's impossible not to use brackets at all, but this'd be ambiguous end end end Also I wrote about syntax like (({:meth.(*args)})) :meth.(*args) which creates a proxy-object having to_proc method - so that it's possible to write (({[1,2,3].map &:to_s.(2)})) [1,2,3].map &:to_s.(2) -- now no dot in such syntax Also it'd be possible to implement some object with syntax like `(({obj(args1)(args2)}))` `obj(args1)(args2)` - obj has method (({#call})) #call that returns object that also has method (({#call})) #call and they are both called. It can be in such a way: (({method(:index)('z')})) method(:index)('z') One problem is that it can behave differently from current behavior in case that method have the same name as a local-variable. Now it works in such a way: p='var'; print p #=> 'var' ## works as local variable p('hi') #=> 'hi' ## works as method call I don't know if it's a spec, I suppose that one mustn't use both variable and method at the same place. So even it's a spec it can be revised in future versions of ruby so that new behaviour would be like that: p='var'; print p #=> 'var' ## works as local variable p('hi') #=> undefined method `call` for 'var':String =end