# Passing the module name into the method definition

**URL:** <https://www.ruby-forum.com/t/passing-the-module-name-into-the-method-definition/78405>\
**Category:** Ruby\
**Created:** [December 5, 2006, 4:52pm UTC](https://www.ruby-forum.com/t/passing-the-module-name-into-the-method-definition/78405 "2006-12-05T16:52:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@shinji](https://www.ruby-forum.com/u/shinji)\
**Post date:** [December 5, 2006, 4:52pm UTC](https://www.ruby-forum.com/t/passing-the-module-name-into-the-method-definition/78405/1 "2006-12-05T16:52:43Z")

</div>

I’ve been building a harness for running watir tests it looks lke this  
currently-

module CVLibrary  
def CVLibrary.cv\_login(testinstance, testaddress, testuser,  
testpass, testldap)  
# opens ie, goes to Central Vision and logs in with the  
# specified address, username, password and domain  
testinstance.goto(testaddress)  
testinstance.frame(“main”).text\_field(:name,  
“username”).set(testuser)  
testinstance.frame(“main”).text\_field(:name,  
“password”).set(testpass)  
testinstance.frame(“main”).select\_list(:name,  
“ldapDir”).select(testldap)  
testinstance.frame(“main”).button(:name, “Login”).click  
end

The test script includes the following  
require ‘watir’  
require ‘test/unit/assertions’  
require ‘CVlibrary’

include Test::Unit::Assertions

ie = Watir::IE.start()

CVLibrary.cv\_login(ie,‘[http://address.html](http://address.html)’,‘name’,‘pass’,‘domain’)

What I don’t understand is why, in the module, I’m explicitly having to  
pass in it’s own name? e.g. CVLibrary.cv\_login

None of the examples

---

<div class="post-metadata">

**Author:** ![shinji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@shinji](https://www.ruby-forum.com/u/shinji)\
**Post date:** [December 6, 2006, 10:52am UTC](https://www.ruby-forum.com/t/passing-the-module-name-into-the-method-definition/78405/2 "2006-12-06T10:52:53Z")

</div>

Max R. wrote:

> I’ve been building a harness for running watir tests it looks lke this  
> currently-
> 
> module CVLibrary  
> def CVLibrary.cv\_login(testinstance, testaddress, testuser,  
> testpass, testldap)  
> …  
> What I don’t understand is why, in the module, I’m explicitly having to  
> pass in it’s own name? e.g. CVLibrary.cv\_login  
> You’re defining a class method (e.g. static in other regions of the  
> programming world).  
> You actually don’t have to pass the module name, and in the interests of  
> refactoring it is also not advised.

You are better off doing:

def self.cv\_login(…)

If you define  
module CVLibrary  
def cv\_login  
end  
end

then you have an instance method, so you need to include the module in a  
class and then call the method from an instance of that class.  
Cheers,  
V.-

---

<div class="post-metadata">

**Author:** ![shinji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@shinji](https://www.ruby-forum.com/u/shinji)\
**Post date:** [December 8, 2006, 4:15pm UTC](https://www.ruby-forum.com/t/passing-the-module-name-into-the-method-definition/78405/3 "2006-12-08T16:15:09Z")

</div>

I don’t believe I am defining a class at all… I had a look at the  
Pragmattic Guide and it seems to do it the same way as I have, and I’ve  
got my head round the instantiation bit now.
