4 ms·
Are you actually passing around methods in Ruby and, if so, why? As I've pointing out in the past (http://news.ycombinator.com/item?id=1141245 http://news.ycomb
by carbon8 16y ago
Are you actually passing around methods in Ruby and, if so, why? As I've pointing out in the past (http://news.ycombinator.com/item?id=1141245 http://news.ycombinator.com/item?id=1141245), passing around methods is very rare in Ruby due to the flexibility of Procs.
- mcantor 16y agoInteresting! I am a half-breed; I write Python at my day job and Ruby in my personal projects. You seem to be suggesting that I am sort of making a mountain out of a molehill. Can you perhaps elaborate on this? I have definitely felt this pain before; I'm not just complaining about it because I "like the Python way more." But if I'm not using Ruby "as intended," I would like to know how I should be using it instead! I feel like the "Python way" is powerful because you don't have to think about whether you're dealing with an anonymous function or a function, whereas in Ruby you must know for sure which one you are dealing with, because they are invoked differently. I'm interested to know how it isn't really a problem, if that's how you feel.
- carbon8 16y agoIt's not a problem in Ruby because you don't pass around method instances, you pass around Procs (wrapped blocks, lambdas and procs), so if you are passing a callable around, you know it's a Proc. If you are passing around a method instance, you should almost certainly be using a block, lambda or proc. Also, see wycats post: http://yehudakatz.com/2010/02/21/ruby-is-not-a-callable-oriented-language/ http://yehudakatz.com/2010/02/21/ruby-is-not-a-callable-orie...
- yxhuvud 16y agoIf you have a method that in python would take a function as a parameter then it usually will be passed as a block in ruby. This doesn't really work if you would want to pass several procs into a method, but honestly, that is not very common.