Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > invoke base class nested method

Reply
Thread Tools

invoke base class nested method

 
 
aidy
Guest
Posts: n/a
 
      04-03-2007
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:


<snip>
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
<snip>

Need to, for example, run the username method?

Thanks

aidy

 
Reply With Quote
 
 
 
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      04-03-2007
On Wed, 4 Apr 2007, aidy wrote:

> 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:
>
>
> <snip>
> 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
> <snip>
>
> 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
--
be kind whenever possible... it is always possible.
- the dalai lama

 
Reply With Quote
 
 
 
 
aidy
Guest
Posts: n/a
 
      04-03-2007
Hi,

Could I do something like this?

$ie = Watir::IE.new
$ie.goto('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

 
Reply With Quote
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      04-03-2007
On Wed, 4 Apr 2007, aidy wrote:

> Hi,
>
> Could I do something like this?
>
> $ie = Watir::IE.new
> $ie.goto('www.updatelog.com')
> class ObjectMap
> def self.login()
> username = $ie.text_field(:name, 'user_name')
> end
> 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
--
be kind whenever possible... it is always possible.
- the dalai lama

 
Reply With Quote
 
aidy
Guest
Posts: n/a
 
      04-03-2007
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

 
Reply With Quote
 
Rick DeNatale
Guest
Posts: n/a
 
      04-06-2007
On 4/3/07, aidy <> wrote:
> 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:
>
>
> <snip>
> 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
> <snip>
>
> 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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Base class method Need base class value Karan Rajput Ruby 2 12-22-2010 04:47 PM
base class public type (non template and template base class) Hicham Mouline C++ 1 04-20-2009 03:28 PM
How to invoke the operator of the private base class? PengYu.UT@gmail.com C++ 1 04-01-2006 01:21 AM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Access of base class' private base class: qualification required, why Alf P. Steinbach C++ 6 09-03-2005 04:03 PM



Advertisments