# Invoke base class nested method

**URL:** <https://www.ruby-forum.com/t/invoke-base-class-nested-method/91017>\
**Category:** Ruby\
**Created:** [April 3, 2007, 9:41pm UTC](https://www.ruby-forum.com/t/invoke-base-class-nested-method/91017 "2007-04-03T21:41:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [April 3, 2007, 9:41pm UTC](https://www.ruby-forum.com/t/invoke-base-class-nested-method/91017/1 "2007-04-03T21:41:05Z")

</div>

Hi,

I have an ObjectMap class that contains other classes. I inherit from  
the base class.Could someone tell me how I can run a nested class  
method from the inherited class?

Here is the code:

class ObjectMap @@ie = Watir::IE.new #each page has a class where objects of that class are mapped class Login def username;@@ie.text\_field(:name, 'user\_name');end def password;@@ie.text\_field(:name, 'password');end def remember\_me;@@ie.checkbox(:name, 'remember\_me');end def sign\_in;@@ie.button(:value, 'Sign in');end end class DashBoard #more methods end end

class A\_Test \< ObjectMap

```
@@ie.goto('www.updatelog.com')
@@ie.maximize
#how do I run the username method?

```

end

Need to, for example, run the username method?

Thanks

aidy

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [April 3, 2007, 10:02pm UTC](https://www.ruby-forum.com/t/invoke-base-class-nested-method/91017/2 "2007-04-03T22:02:08Z")

</div>

On Wed, 4 Apr 2007, aidy wrote:

> class ObjectMap  
> end
> 
> Need to, for example, run the username method?
> 
> Thanks
> 
> aidy

many ways. make it easy on yourself though

class ObjectMap  
def self.login() Login end  
end

class A\_Test \< ObjectMap

```
@@ie.goto('www.updatelog.com')
@@ie.maximize
#how do I run the username method?

login.username

```

end

-a

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [April 3, 2007, 10:46pm UTC](https://www.ruby-forum.com/t/invoke-base-class-nested-method/91017/3 "2007-04-03T22:46:16Z")

</div>

Hi,

Could I do something like this?

$ie = Watir::IE.new  
$ie.goto(‘[www.updatelog.com](http://www.updatelog.com)’)  
class ObjectMap  
def self.login()  
username = $ie.text\_field(:name, ‘user\_name’)  
end  
end

class A\_Test \< ObjectMap

```
login.username.set('aidy')

```

end

I am not so sure why you have used a self prefix before the login  
method.

Thanks

Aidy

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [April 3, 2007, 10:51pm UTC](https://www.ruby-forum.com/t/invoke-base-class-nested-method/91017/4 "2007-04-03T22:51:17Z")

</div>

On Wed, 4 Apr 2007, aidy wrote:

> end  
> if you’re a fan of debugging code with lots of global variables - sure.

> class A\_Test \< ObjectMap
> 
> login.username.set(‘aidy’)  
> end
> 
> I am not so sure why you have used a self prefix before the login  
> method.

it’s a class method.

-a

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [April 3, 2007, 11:21pm UTC](https://www.ruby-forum.com/t/invoke-base-class-nested-method/91017/5 "2007-04-03T23:21:20Z")

</div>

Thanks for your advice.

What I mean to ask is that once I have entered the class method  
(self.login()) can I  
then assign

username=ie.text\_field(:name, ‘user\_name’)

and invoke this assignment in the sub class

class A\_Test \< ObjectMap

```
login.username

```

end

?

Or something like that

cheers

aidy

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [April 6, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/invoke-base-class-nested-method/91017/6 "2007-04-06T15:15:28Z")

</div>

On 4/3/07, aidy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> class ObjectMap  
> end
> 
> Need to, for example, run the username method?

Same way you’d do it from the superclass:

class A\_Test \< ObjectMap  
Login.new.username  
end

Note that username is not a method of ObjectMap but of the nested  
class ObjectMap::Login

You could also do this from outside ObjectMap and it’s subclasses like  
so:

ObjectMap::Login.new.username

If you made login and it’s brethren class methods:

class Login  
def self.username;@@ie.text\_field(:name, ‘user\_name’);end  
def self password;@@ie.text\_field(:name, ‘password’);end  
def self.remember\_me;@@ie.checkbox(:name, ‘remember\_me’);end  
def sign\_in;@@ie.button(:value, ‘Sign in’);end  
end

Then the above would be

class A\_Test \< ObjectMap  
Login…username  
end

or from outside:

ObjectMap::Login.username

Lacking more information about what you are really trying to  
accomplish, your code looks a little odd to my eye.

ObjectMap seems like it really should be a module rather than a class  
since from what you’ve shown it’s really acting as what looks like a  
name space.

You’re using class variables which always raises a yellow flag in my  
mind.

Of course some of this could be Watir practice and I’ve never used  
Watir.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)
