'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.com>wrote:

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

Reply via email to