On 19.05.2008 22:28, Guoliang Cao wrote:
> Hi,
> 
> I don't consider myself a ruby guru but have been a ruby user for a few
> years. Since ruby 1.9 is out but its feature set is not finalized, guess
> it's ok to voice my opinions on what may be interesting to a joe user.
> 
> Currently Ruby has 2 kinds of callable block - proc and lambda, which
> are slightly different on semantics. Other than those, is it possible to
> make methods work similarly (maybe like a lambda plus an implicit self
> parameter)? This will make it closer to the statement "everything is an
> object" - a method is an object too. This also makes Ruby a next level
> functional language I guess. To refer to the method object, we probably
> can use syntax like this:
> 
> m = obj->do_something
> m[1,2,3]
> 
> m = Dir->pwd
> m[]

This does exist already although the syntax is slightly different:

irb(main):003:0> RUBY_VERSION
=> "1.8.5"
irb(main):004:0> m = "foo".method :length
=> #<Method: String#length>
irb(main):005:0> m.call
=> 3
irb(main):006:0> m = String.instance_method :length
=> #<UnboundMethod: String#length>
irb(main):007:0> m.bind("foo").call
=> 3
irb(main):008:0> m.bind("foo")
=> #<Method: String#length>
irb(main):009:0> m.bind("foo")[]
=> 3
irb(main):010:0> m = "foo".method(:<<)
=> #<Method: String#<<>
irb(main):011:0> m["bar"]
=> "foobar"
irb(main):012:0>

Note also that you can achieve something similar via send and this is 
often sufficient.

> Method object may work similar to lambda and be passed as parameter.
> Down the way, partial invocation can be added by associating a context
> to the method object and memorizing parameter values. i.e.
> 
> m = obj->do_something 1,2,3
> m[]

This is only possible using lambdas AFAIK, i.e. you cannot stick method 
parameters into a method.

> What do you guys think? any comments are welcome.

With these questions I always ask myself what do we gain by such a 
change?  All changes have some effort attached, some more and some less. 
  But it's not worthwhile if the effort outweighs the benefits.  What do 
you think are the benefits of this change?  Why should we do it?

Kind regards

	robert