From: Chris Pine Date: 2003-04-10T05:59:04+09:00 Subject: Re: Proc Question ----- Original Message ----- From: "Brian Candler" > You can call this method simply by writing `fiveSquared', and Ruby *knows* > you want the method called, because that's the only thing you can do with > methods. Well, there's a bit more to it than that really. ---------------------------- Yes, but your explanation has more to do with how Ruby determines what's a method and what's a variable. I just meant that there's nothing you can do with methods but call them; that they aren't objects. ---------------------------- Furthermore, a method (once defined) is in fact an object, or at least you can get hold of an object which encapulates it: ---------------------------- Which isn't quite the same thing... of course instances of the Method class are objects. In fact: irb(main):001:0> method(:puts).id => 537316732 irb(main):002:0> method(:puts).id => 537311592 Method objects wrap methods. ---------------------------- > have such different syntaxes (syntices?). Same for method parameter list > `(...)' and block parameter list `|...|'. The block parameter list is closer to parallel assignment than a method call. e.g. the following are pretty much the same: ---------------------------- I don't know what you mean by that. They are all three similar, as is this: irb(main):003:0> a = [3,4,5] => [3, 4, 5] irb(main):004:0> b = [1,2,*a] => [1, 2, 3, 4, 5] Because they all use arrays (as I understand it). How about this? irb(main):005:0> case 3 irb(main):006:1> when *b then puts 'yep' irb(main):007:1> end yep => nil The beginning of a method binds the parameters to the arguments passed in (I hope I'm getting my vocabulary right) in exactly the same way, again, as I understand it. ---------------------------- Ruby doesn't have "functions" - it does have Methods and Procs. ---------------------------- What do you think a proc is? You can even create one with `lambda'! We all agree that they are closures, right? Closures are functions (with certain properties, of course) by any definition I have ever seen. A proc is just a wrapped function, and you call it (the function) with the `call' method (i.e. calling the proc's method). I don't think OO purity is achieved by: alias :proc :function :) Methods, on the other hand, seem quite different to me (even if they are implemented with procs much like parameter lists are implemented with arrays). It seems like, instead of being bound to any particular environment, they are just bound "to the object". Plus, they are shared between all objects of that class... that's a big difference. You would need a different proc for each object to get the same effect. Chris