[wtr-general] Re: How to print all the methods in the Class or Module out?

2009-03-13 Thread marekj
'require' and 'include' are completely two different concepts.
When you require a ruby file you tell the current file to look for classes
and modules in that file when needed, also any code not wrapped in method
will be executed on require automatically. So you have to 'require' other
file before you can 'include' modules that it owns. it's not either-or
proposition.

When you include a module into a class your class inherits methods defined
in the module as it's own.
You can see this in a decorator pattern. here is a good simple example with
Coffee and Cream module
http://ruby.simapse.com/2008/08/test.html

Let's say you have a 1 bedroom apartment and one day you buy another 1
bedroom apartment next to yours. Now you are the owner of two apartments and
you are free to go next door and use anything in that apartment for your
needs in your first apartment.
Include is like if one day you decide to knock the walls between two
apartments and make it one. Therefore you no longer have to go next door, it
is now part of your apartment.

(disclaimer: I am hoping to write about Metaphors We Ruby By. how am I
doing?)
marekj

Watirloo: Semantic Page Objects in UseCases
http://github.com/marekj/watirloo/



On Thu, Mar 12, 2009 at 5:54 PM, Chuck van der Linden sqa...@gmail.comwrote:


 I'm still learning a lot regarding how ruby handles modules, classes
 etc..

 but in general, woudln't using require instead of include solve his
 problem?  (unless he's actually extending or subclassing stuff from
 the modules)

 I thought I remember seeing something about a lot of folks using
 include 'watir' when they should be using require 'watir'

 On Mar 12, 3:00 pm, marekj marekj@gmail.com wrote:
  On Thu, Mar 12, 2009 at 4:38 AM, wesley chen cjq@gmail.com wrote:
   Thanks, :), it is exactly what I want.
 
   I ask this kind of questions because I find, in my code, I use too
 many:
   include module.
   When I include the module into the class, all the methods in the module
   comes into the class's method. That's terrible.
 
  to remove the 'terrible' from listing do this use Object.local_methods
  patch.
 
  class Object
def local_methods
  (methods - Object.instance_methods).sort
end
  end
 
  so if you have
 
  class Foo
def foo
  'foo'
end
  end
 
  then Bla.new.local_methods #= ['foo']
  if you want methods defined only as instances of that object.
  useful.
  Wirble uses it for irb inspectionhttp://pablotron.org/software/wirble/
 
  marekj
 
  Watirloo: Semantic Page Objects in UseCases
  Human Readable Machine Executable Acceptance Testinghttp://
 github.com/marekj/watirloo/
 
 
 
 
 
   Thanks.
   Wesley Chen.- Hide quoted text -
 
  - Show quoted text -
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---



[wtr-general] Re: How to print all the methods in the Class or Module out?

2009-03-12 Thread Željko Filipin
On Thu, Mar 12, 2009 at 10:18, wesley chen cjq@gmail.com wrote:
 How to print the methods in the class or module out?

Wesley,

you need this?

 a = 
= 
 a.methods
= [%, select, []=, inspect, , each_byte, clone, method,
gsub, casecmp, public_methods, to_str, partition, tr_s,
...
capitalize!, scan, []]



Željko

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---



[wtr-general] Re: How to print all the methods in the Class or Module out?

2009-03-12 Thread wesley chen
Thanks.

class.instance_methods
module.instance_methods make it.


Thanks.
Wesley Chen.


On Thu, Mar 12, 2009 at 5:32 PM, wesley chen cjq@gmail.com wrote:

 Hi, Zeljko,
 Sorry, I have not demonstrated clearly enough.

 Suppose I have written a module or a class, in the module or class, I have
 written many methods. I would like to print all my methods out.
 How can I make it?


 Any suggestion would be appreciated.
 Thanks.
 Wesley Chen.


 On Thu, Mar 12, 2009 at 5:24 PM, Željko Filipin
 zeljko.fili...@wa-research.ch wrote:

 On Thu, Mar 12, 2009 at 10:18, wesley chen cjq@gmail.com wrote:
  How to print the methods in the class or module out?

 Wesley,

 you need this?

  a = 
 = 
  a.methods
 = [%, select, []=, inspect, , each_byte, clone, method,
 gsub, casecmp, public_methods, to_str, partition, tr_s,
 ...
 capitalize!, scan, []]



 Željko

 



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---



[wtr-general] Re: How to print all the methods in the Class or Module out?

2009-03-12 Thread wesley chen
Hi, Zeljko,
Sorry, I have not demonstrated clearly enough.

Suppose I have written a module or a class, in the module or class, I have
written many methods. I would like to print all my methods out.
How can I make it?


Any suggestion would be appreciated.
Thanks.
Wesley Chen.


On Thu, Mar 12, 2009 at 5:24 PM, Željko Filipin
zeljko.fili...@wa-research.ch wrote:

 On Thu, Mar 12, 2009 at 10:18, wesley chen cjq@gmail.com wrote:
  How to print the methods in the class or module out?

 Wesley,

 you need this?

  a = 
 = 
  a.methods
 = [%, select, []=, inspect, , each_byte, clone, method,
 gsub, casecmp, public_methods, to_str, partition, tr_s,
 ...
 capitalize!, scan, []]



 Željko

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---



[wtr-general] Re: How to print all the methods in the Class or Module out?

2009-03-12 Thread Željko Filipin
On Thu, Mar 12, 2009 at 10:32, wesley chen cjq@gmail.com wrote:
 I would like to print all my methods out.

And this is not what you need?

class MyClass
  # some code
end

variable = MyClass.new
variable.methods

Željko

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---



[wtr-general] Re: How to print all the methods in the Class or Module out?

2009-03-12 Thread SuperKevy

Brilliant!

On Mar 12, 4:34 am, Željko Filipin zeljko.fili...@wa-research.ch
wrote:
 On Thu, Mar 12, 2009 at 10:32, wesley chen cjq@gmail.com wrote:
  I would like to print all my methods out.

 And this is not what you need?

 class MyClass
   # some code
 end

 variable = MyClass.new
 variable.methods

 Željko
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---



[wtr-general] Re: How to print all the methods in the Class or Module out?

2009-03-12 Thread marekj
On Thu, Mar 12, 2009 at 4:38 AM, wesley chen cjq@gmail.com wrote:

 Thanks, :), it is exactly what I want.

 I ask this kind of questions because I find, in my code, I use too many:
 include module.
 When I include the module into the class, all the methods in the module
 comes into the class's method. That's terrible.


to remove the 'terrible' from listing do this use Object.local_methods
patch.

class Object
  def local_methods
(methods - Object.instance_methods).sort
  end
end


so if you have

class Foo
  def foo
'foo'
  end
end


then Bla.new.local_methods #= ['foo']
if you want methods defined only as instances of that object.
useful.
Wirble uses it for irb inspection
http://pablotron.org/software/wirble/



marekj

Watirloo: Semantic Page Objects in UseCases
Human Readable Machine Executable Acceptance Testing
http://github.com/marekj/watirloo/






 Thanks.
 Wesley Chen.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---



[wtr-general] Re: How to print all the methods in the Class or Module out?

2009-03-12 Thread Chuck van der Linden

I'm still learning a lot regarding how ruby handles modules, classes
etc..

but in general, woudln't using require instead of include solve his
problem?  (unless he's actually extending or subclassing stuff from
the modules)

I thought I remember seeing something about a lot of folks using
include 'watir' when they should be using require 'watir'

On Mar 12, 3:00 pm, marekj marekj@gmail.com wrote:
 On Thu, Mar 12, 2009 at 4:38 AM, wesley chen cjq@gmail.com wrote:
  Thanks, :), it is exactly what I want.

  I ask this kind of questions because I find, in my code, I use too many:
  include module.
  When I include the module into the class, all the methods in the module
  comes into the class's method. That's terrible.

 to remove the 'terrible' from listing do this use Object.local_methods
 patch.

 class Object
   def local_methods
     (methods - Object.instance_methods).sort
   end
 end

 so if you have

 class Foo
   def foo
     'foo'
   end
 end

 then Bla.new.local_methods #= ['foo']
 if you want methods defined only as instances of that object.
 useful.
 Wirble uses it for irb inspectionhttp://pablotron.org/software/wirble/

 marekj

 Watirloo: Semantic Page Objects in UseCases
 Human Readable Machine Executable Acceptance 
 Testinghttp://github.com/marekj/watirloo/





  Thanks.
  Wesley Chen.- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---