4 ms·
Procs, blocks, and methods are actually all different from each other. Of those three, Procs are the only ones that are actually objects (i.e., can be assigned
by jfarmer 17y ago
Procs, blocks, and methods are actually all different from each other.
Of those three, Procs are the only ones that are actually objects (i.e., can be assigned to variables and can receive messages).
- sjs 17y agoputs_method = method(:puts) def get_block(&block) block end my_block = get_block { puts_method.call('hello!') } my_block.call #=> hello!
- tesseract 17y agoputs puts_method.class #=> Method puts my_block.class #=> Proc Method and Proc are types; blocks are a syntactic construct.
- sjs 17y agoYou're right, captured blocks are instances of Proc. However I still claim that methods are objects that can be passed around, assigned to variables, and sent messages. Method and UnboundMethod are both classes that inherit from Object. It's right there in proc.c with the Proc class. Method.ancestors #=> [Method, Object, Kernel]
- tesseract 17y agoI don't disagree with you there.
- jfarmer 17y agoDidn't know that. Ruby, you crazy.