[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:04039] Re: Pluggable functions and blocks

From: Dave Thomas <Dave@...>
Date: 2000-07-15 15:46:56 UTC
List: ruby-talk #4039
matz@netlab.co.jp (Yukihiro Matsumoto) writes:

>    String.instance_method(:gsub).call("abc", /a/, "b") # => "bbc"
>    String.instance_method(:gsub).call(42, /a/, "b")    # => TypeError

Works great, but I'm wondering. That mixed parameter list doesn't seem 
very elegant. How about keeping on with the current rule: you can only 
call a Method object, one that's bound to a receiver. Then provide
UnboundMethod#bind_to, which returns a Method. Then you'd rewire the
above as

     unbound = String.instance_method(:gsub)
     unbound.bind_to("abc").call(/a/, "b") # => "bbc"

You could then provide the symetrical Method#unbind

     bound = "abc".method(:gsub)
     unbound = bound.unbind   # => UnboundMethod


This all seems to have a clearer semantic, and also allows you to
change the state of method objects on the fly.


Anyway, I know what you're doing really. You're just trying to make
sure that we _never_ get this book finished ;-)



Regards


Dave

In This Thread