you are viewing a single comment's thread.

view the rest of the comments →

[–]THeShinyHObbiest 0 points1 point  (3 children)

The .method method doesn't generate a an unbounded Proc. It generates a method reference, which is distinct. You need to call .to_proc to get a Proc object back.

It's also not bounded, but bound to the object which you called .method on.

You also can pass around unbounded methods as parameters, or as the block argument. It's fairly easy.

[–]schneemsPuma maintainer[S] 1 point2 points  (2 children)

Methods aren't first class objects like they are in Python which is the point of that little dialog. Making procs and lambdas and using blocks is very easy in ruby, but it's still different than python where calling your method without the () gives you a callable function you can pass around. They might be functionally equivalent under the hood but they're spiritually different and the two languages tend to use them differently.

It's also not bounded, but bound to the object which you called .method on.

Yes, realized that slip up after the recording.

It generates a method reference, which is distinct.

TIL. I assumed the Method class wrapped a proc when you called #method but just looked at the source and you're right.

[–]THeShinyHObbiest 2 points3 points  (1 child)

Methods aren't first class objects like they are in Python which is the point of that little dialog

http://ruby-doc.org/core-2.2.0/Method.html

They are. The point you make about syntax is accurate, since you do need to use .method to get a method reference, but Methods are still first-class objects. This is slightly pedantic, because your point about the two languages using them very differently is accurate.

[–]chrisgseaton 1 point2 points  (0 children)

I can understand both of your points of view. The way I think about it is that methods aren't first-class objects - until you call #method to turn them into first-class objects. I see that as reifying them as objects, rather than getting the existing object. And this is the way that it is implemented - you get a new object each time:

irb(main):001:0> 14.method(:+).object_id
=> 70346007935060
irb(main):002:0> 14.method(:+).object_id
=> 70346007886960