N
Nickolay Kolev
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.
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
in test.rb:
require 'fruby'
def times_two(x)
x * 2
end
p Functional.everytimes_two, [1,2,3])
And I get this:
undefined method `f' for Functional:Module (NoMethodError)
How do I pass the times_two function to the module method?
Many thanks in advance!
-- Nicky
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.
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
in test.rb:
require 'fruby'
def times_two(x)
x * 2
end
p Functional.everytimes_two, [1,2,3])
And I get this:
undefined method `f' for Functional:Module (NoMethodError)
How do I pass the times_two function to the module method?
Many thanks in advance!
-- Nicky