[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

inclusion of module: differences

Leon Bogaert

5/28/2008 10:28:00 PM

Hi all!

I have this code: http://pastie.caboo...

And the output of that script is:

"Included from Array3"
"Included from Array"
"Included from Array2"
"[]"
"[]"
"aaarghhhh..."
nil

Obiously the difference in output is because I include the module in
different ways. But why is it different? Am I doing something wrong?
Should I use class_eval or something?

Thanks in advance!

Leon
--
Posted via http://www.ruby-....

4 Answers

Calamitas

5/29/2008 9:55:00 AM

0

On Thu, May 29, 2008 at 12:27 AM, Leon Bogaert <leon@tim-online.nl> wrote:
> Hi all!
>
> I have this code: http://pastie.caboo...
>
> And the output of that script is:
> <snip>
>
> Obiously the difference in output is because I include the module in
> different ways. But why is it different? Am I doing something wrong?
> Should I use class_eval or something?

Appending this to your test code may be enlightening:

p a.class.ancestors # => [Array, InstanceMethods, Enumerable, Object, Kernel]
p a2.class.ancestors # => [Array2, Array, InstanceMethods,
Enumerable, Object, Kernel]
p a3.class.ancestors # => [Array3, InstanceMethods, Array,
InstanceMethods, Enumerable, Object, Kernel]

This gives an indication of the search order for method lookup. For
'a' which is an instance of Array, the inspect method is found in the
Array class and included modules are thus not checked. Because you
included InstanceMethods in array already, including it in Array2
doesn't do anything because Ruby tries to include a module only once
in each class/module. Because the include in Array3 happens before the
one in Array, it is actually performed because Ruby cannot foresee
that you are about to include the same module in Array. So in case of
Array3, InstanceMethods comes before Array in the method lookup path,
in case of Array2 it doesn't.

So basically, the order of includes in Ruby matters. Also, redefining
methods of a class by including a module doesn't always work because
the module is put underneath the class, not on top of it. It only
works if the method is defined in a superclass of the class where you
include that module. (Still wishing Ruby had a preclude method...)

Peter

Leon Bogaert

5/29/2008 7:59:00 PM

0

Wow, thanks Peter! That was very enlightening!
--
Posted via http://www.ruby-....

H?ctor Miguel

5/24/2009 7:56:00 AM

0

hi, Art !

> ... when I select the whole sheet, I get the error, overflow.
> How can I Correct this?

for xl2007 change this:

If Selection.Count > 1 Then Exit Sub

to this:

If Selection.CountLarge > 1 Then Exit Sub

regards,
hector.

__ previous __
>>> Hoe do I write the code, if the selection is anything but one cell
>>> So if I select a range all thew whole page, or a tab or a button etc.
>>> it should ignore everything, only when I select one cell then it should do ...
>>
>> i.e.
>>
>> Sub mySub()
>> If TypeName(Selection) <> "Range" Then Exit Sub
>> If Selection.Count > 1 Then Exit Sub
>> MsgBox "What's next ?", , ""
>> End Sub


royUK

5/24/2009 8:07:00 AM

0


You must be usng Excel 2007, there are too many cells for count to
handle.
Why select all cells I doubt if all the cells in 2007 will ever be
used, use UsedRange or CurrentRegion insteadnstead


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.exc...)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php...
View this thread: http://www.thecodecage.com/forumz/showthread.p...