From: gabriele renzi Date: 2005-07-31T20:31:03+09:00 Subject: Re: Higher Order Functions Nickolay Kolev ha scritto: > Hi guys, > > I have recently started learning Ruby having some background in Python > and Prolog. Being a fan of functional programming I want to port the > goopy functions (http://goog-goopy.sourceforge.net/ > goopy.functional.html) in Ruby despite most of them having > straightforward equivalents in Ruby already. Just as an exercise. I > also saw it as a good way to teach myself about modules. And eventually > about unit testing. :-) great plan :) even if I'm a bit disappointed that the library seem to be (almost) a list handling library. > My plan is to put all the functions in a module called Functional and > call them like Functional.func_name(params). > > in fruby.rb: > > module Functional > > def Functional.every(f, lst) > lst.collect { |element| f(element) } > end > > end Notice you could just do module Functional def every... end def any other... end extend self end so that you could call it via Functiona.f and yet retain the ability to include the module (say, in Enumerable ;) I also second the suggetsion to generally use a block wehenever possible (i.e. 99% of the time)