A problem with that is that Ruby modules are all about providing constants and methods to the classes that include them. But I want real functions (lambdas), not methods.
The `defn` method within Stunted lets you add functions to modules in a way that mades them as usable as methods.
https://github.com/marick/stunted/wiki/Defn
-----
Brian Marick, Artisanal Labrador
Now working at http://path11.com
Contract programming in Ruby and Clojure
Occasional consulting on Agile
Why are Proc-like objects a problem?
> A problem with that is that Ruby modules are all about providing constants and methods to the classes that include them. But I want real functions (lambdas), not methods.
On Jan 17, 2012, at 2:49 PM, Steve Klabnik wrote:
> Why are Proc-like objects a problem?
On Jan 17, 2012, at 2:51 PM, Robert D Pitts wrote:
> I think it's the inconvenience/kludginess of unbinding the method, no?
On Jan 17, 2012, at 2:58 PM, Steve Klabnik wrote:
> I guess what I mean is 'why is the binding a problem?'
Not sure I understand these questions. Here's a reason I want `include MyModule` to give me lambdas, not just methods and constants. Suppose I want to provide a pile of lambdas to use in higher-order ways. Modules are my chosen (for now) way to group piles of things, but Ruby assumes those things are either constants or methods. So to make lambdas accessible via modules, I make methods that return those lambdas. `defn` is just a shorthand way of doing that. So, for example, I can do this:
ruby-1.9.2-p290 :006 > module M
ruby-1.9.2-p290 :007?> include Stunted::Defn
ruby-1.9.2-p290 :008?> defn :add, -> a, b { a + b }
ruby-1.9.2-p290 :009?> end
ruby-1.9.2-p290 :010 > include M
ruby-1.9.2-p290 :016 > add2 = add.curry.(2)
ruby-1.9.2-p290 :017 > add2.(3)
=> 5