From: Mike Edgar Date: 2011-09-26T05:38:34+09:00 Subject: [ruby-core:39707] Re: [Ruby 1.9 - Feature #5364] How about new syntax: "object.\method" returns a Method instance? Of note, there is already a working patch (for a very similar feature) for the 1.9 branch at the ruby-patches github repo [0], ported from the old Suby experiment project [1]. It doesn't use ".\", just "\" and has an implicit self form, too. So: \class # => # 1\+ # => # "hello"\` # => # "hi"\class.class # => Method "hi"\class\type\class # => # [0] https://github.com/michaeledgar/ruby-patches/tree/master/1.9/method_operator [1] http://rubyforge.org/projects/suby/ On Sep 25, 2011, at 4:13 PM, Eric Hodel wrote: > > Issue #5364 has been updated by Eric Hodel. > > Category set to core > > =begin > I find myself rarely needing to call #method and I don't often see code where other people call #method, so I don't see the need to add special syntax for it. Is there a reason why you use #method very often and that having a more compact syntax would help? > > Note that \ can be used at the end of a line to continue it to the next line: > > return \ > really_long_expression > =end > > ---------------------------------------- > Feature #5364: How about new syntax: "object.\method" returns a Method instance? > http://redmine.ruby-lang.org/issues/5364 > > Author: Joey Zhou > Status: Open > Priority: Normal > Assignee: > Category: core > Target version: > > > I'm afraid the normal way of creating a Method instance is circuitous and a bit hard to write: > > a_method = object.method(:method_name) > > I find the way of obtaining a function/method object in Python is so easy, for example, "str.split()" returns a list, while "str.split" (without parentheses) returns a method object. However, parenthesis in Ruby is always optional, so this road is blocked. > > Well, how about "object.\method" style? You can type "str.\split" to get "str.method(:split)". > > The reasons are: > > 1. It makes people happy, writing less code, and no harm to readability. > > 2. "\" is not a frequently used token. It can only be used in strings, regexps (or any else?). I think using this token leads to no ambiguity. > > 3. "\" is like Perl's referrence symbol. In Perl, you can use "$f = \&func;" to make a referrence to the function. In Ruby, "&" seems unnecessary. > > 4. It enhances the consistency of the language syntax. There are two correlative methods "Object#send" and "Object#method", but... > > str.send(:split) == str.split > str.method(:split) == ??????? > > If adding this new syntax, it looks more pretty: > > str.method(:split) == str.\split > > > > -- > http://redmine.ruby-lang.org >