Multi-Methods is a library for creating dynamically-dispatched methods in a ruby class. What does this mean? Well, I’m not the one to explain it, but I look at it as a nice way to extract if-statements from your code, since, as we all know, ‘if-statements are evil.’
This is also a small project to show Jon Kern some interesting aspects of Ruby programming.
Here’s a couple simple examples (you can look at the cucumber features, as well):
class PathMan
include MultiMethods multi_method :route_me do router {|*args| args[0] == true ? :path_one : :path_two} implementation_for :path_one do |*args| "you called path one" end implementation_for :path_two do |*args| "you called path two" end end
end
allows you to call
p = PathMan.new p.route_me true #=> “you called path one” p.route_me false #=> “you called path two”
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. If you don’t have tests, it will not get integrated.
-
Commit, do not mess with rakefile, version, or history.
-
Send me a pull request. Bonus points for topic branches.
Copyright © 2009 Corey Haines. See LICENSE for details.