so i decided to learn ruby and just wanted to make sure im learning correctly.
using (in ruby) module.method(variable) is this equivalent to namespace::function(arguements)?
This is a C++ forum, you'd get better answers on a Ruby form. Then again, I am a ruby developer by trade so I can answer this.
The short answer is "sortof". The long answer is that modules serve a very different purposes than namespaces, but can be used in that purpose if you desire. Modules are typically used for Mixins, which allow you to dynamically add methods to objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
module Foo
def say_hello
puts "hello world"
end
end
class Bar
end
x = Bar.new
puts x.respond_to? :say_hello
class Bar
include Foo
end
puts x.respond_to? :say_hello
x.say_hello
I know, noticed how I answered him anyway? This is entry-level Ruby stuff though, and is answered in the documentation/wiki/website/beginner ruby forums. I was trying to direct him to a place that might be better suited to helping him learn.