Project

General

Profile

Actions

Feature #6672

closed

Calling #() without dot before braces

Added by prijutme4ty (Ilya Vorontsov) over 11 years ago. Updated over 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:45973]

Description

=begin
It looks odd to call Proc/Method (({pr})) using (({pr.(*args)})) or (({pr[*args]})) syntax. Why not to use (({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})) method

So I suggest syntax (({x.(*args,&block)})) alias to (({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

Also I wrote about syntax like (({: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)})) -- now no dot in such syntax

Also it'd be possible to implement some object with syntax like (({obj(args1)(args2)})) - obj has method (({#call})) that returns object that also has method (({#call})) and they are both called.
It can be in such a way: (({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


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #7346: object(...) as syntax sugar for object.call(...)Rejectedmatz (Yukihiro Matsumoto)11/13/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0