module Test
def test # This is an instance method
puts "test"
end
puts "testing"
test # This is a call to a module method
end
The two are completely unrelated. Somewhere higher up in your inheritance chain, you have a module method named test
which takes at least one argument. (I'm guessing it is the Kernel#test
method, which takes two arguments.) Since you call it without an argument, you get an ArgumentError
exception.
If you were to provide a little more detail about what the actual problem is, that you are trying to solve, it would be possible to give a better answer. Until then, here's a couple of ideas:
Make the method a module method:
module Test
def self.test; puts "test" end
puts "testing"
test
end
Extend the module with itself:
module Test
def test; puts "test" end
extend self
puts "testing"
test
end
Create an instance of the module:
module Test
def test; puts "test" end
end
puts "testing"
Object.new.extend(Test).test
Mix the module into a class, and create an instance of that:
module Test
def test; puts "test" end
end
class Foo; include Test end
puts "testing"
Foo.new.test
Mix the module into Module
:
module Test
def test; puts "test" end
end
class Module; include Test end
module Test
puts "testing"
test
end
Mix the module into Object
:
module Test
def test; puts "test" end
end
class Object; include Test end
puts "testing"
test
Mix the module into the main
object:
module Test
def test; puts "test" end
end
include Test
puts "testing"
test