Une méthode n'est pas une valeur — il faut la demander.A method isn't a value — you have to ask for one.
Le Vol 6 manipule classes et méthodes à l'exécution ; ce numéro part de la plus discrète de ces manipulations. Contrairement à JavaScript ou Python, en Ruby une méthode n'est pas un objet de première classe : la définir ne te rend aucune valeur transportable, et écrire son nom seul lève une NameError. Tu peux pourtant réifier une méthode — en demander un objet, via obj.method(:nom). Tu obtiens un Method, qu'on appelle avec .call exactement comme un proc ou une lambda. Mais pourquoi cette étape de plus ? Pourquoi les méthodes ne sont-elles pas first-class d'office ? Parce que Ruby, langage purement objet dans la lignée de Smalltalk, sépare une chose qu'on confond presque toujours : la méthode et le message.Vol 6 manipulates classes and methods at runtime; this issue starts from the quietest of those manipulations. Unlike JavaScript or Python, in Ruby a method is not a first-class object: defining it hands you no value to carry, and writing its name alone raises a NameError. You can still reify a method — ask for an object representing it, via obj.method(:name). You get a Method, called with .call exactly like a proc or a lambda. But why this extra step? Why aren't methods first-class out of the box? Because Ruby, a purely object-oriented language in the Smalltalk lineage, separates a thing we almost always conflate: the method and the message.
class Greeter def hello(name) = "Bonjour, #{name}" end g = Greeter.new g.hello("Ada") # => "Bonjour, Ada" un message hello envoyé à g hello # NameError : aucune valeur libre nommée hello # ↑ définir une méthode ne crée AUCUN objet à passer m = g.method(:hello) # on DEMANDE un objet qui représente la méthode m.class # => Method m.call("Ada") # => "Bonjour, Ada" appelable comme un proc/lambda m.owner # => Greeter d'où vient l'implémentation
Un message est le nom d'une responsabilité ; une méthode est un bout de code concret qui en réalise une version. Envoyer g.hello, c'est laisser g chercher, maintenant, quelle méthode répond. Demander g.method(:hello), c'est figer cette réponse dans un objet.A message is the name of a responsibility; a method is a concrete piece of code realizing one version of it. Sending g.hello lets g look up, now, which method answers. Asking g.method(:hello) freezes that answer into an object.
« Pour faire circuler un comportement, je passe l'objet et j'envoie le message — pas un obj.method(:m). » L'objet Method a ses usages, mais c'est un instantané : on verra qu'il fige l'implémentation au moment de la capture, alors qu'un message est ré-résolu à chaque envoi."To pass a behavior around, I hand over the object and send the message — not an obj.method(:m)." The Method object has its uses, but it's a snapshot: we'll see it freezes the implementation at capture time, whereas a message is re-resolved on every send.
Le choix de ne pas rendre les méthodes first-class d'office est cohérent avec la nature de Ruby, langage purement objet à la Smalltalk. Alan Kay voyait les objets comme des cellules indépendantes qui s'envoient des messages, sans présumer de la manière dont ils seront traités. Passer des références à des méthodes précises, c'est court-circuiter cette indirection — et s'exposer à ce que la référence se périme. Tout le numéro déplie ce coût.The choice not to make methods first-class out of the box is consistent with Ruby's nature as a purely object-oriented, Smalltalk-style language. Alan Kay saw objects as independent cells sending each other messages, with no assumptions about how they'd be handled. Passing references to specific methods short-circuits that indirection — and risks the reference going stale. The whole issue unpacks that price.