T
Thomas Hafner
Hello,
how should I group some stateless functions into a module and use them
in a very simple way without littering the namespace? E.g. if the
module is ``Foo'' with at least one function foo, then I'd like to use
that module in a way as simple like that:
require 'Foo'
puts Foo.foo("world")
The first solution that I've found is to write Foo.rb like follows:
module Foo
def foo(s)
"Hello, #{s}\n"
end
end
class << Foo
include Foo
end
Is that Ok? Or is there even a simpler way?
Regards
Thomas
how should I group some stateless functions into a module and use them
in a very simple way without littering the namespace? E.g. if the
module is ``Foo'' with at least one function foo, then I'd like to use
that module in a way as simple like that:
require 'Foo'
puts Foo.foo("world")
The first solution that I've found is to write Foo.rb like follows:
module Foo
def foo(s)
"Hello, #{s}\n"
end
end
class << Foo
include Foo
end
Is that Ok? Or is there even a simpler way?
Regards
Thomas