[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

self.included(base) and base.class_eval problems, etc.

n8agrin

3/8/2006 7:35:00 AM

I spent a whole night trying to figure out why a module I was including
wasn't producing any results.

I finally narrowed it down to this bit of code in the module:

def self.included(base)
base.send :current_user, :logged_in?, :user?
end

For some reason, commenting it out lets everything run fine, and it
seems that leaving it in causes the module to fail silently.

Can someone explain to me what this is doing? I've seen similar calls
to self.included(base) which ended with base.extend(SomeModule).

I searched high and low for documentation on this, but found nothing.
My best guess is it's some quasi-magic method that's trying to allow
ActionView to use these methods as well. Any idea why it's failing or
where I can read up on this?

Thanks!

2 Answers

vanekl

3/8/2006 1:09:00 PM

0

James Gray

3/8/2006 1:54:00 PM

0

On Mar 8, 2006, at 1:38 AM, n8agrin@gmail.com wrote:

> I spent a whole night trying to figure out why a module I was
> including
> wasn't producing any results.
>
> I finally narrowed it down to this bit of code in the module:
>
> def self.included(base)
> base.send :current_user, :logged_in?, :user?
> end
>
> For some reason, commenting it out lets everything run fine, and it
> seems that leaving it in causes the module to fail silently.

The default included() is what adds the methods, so you need to add a
call to super to keep that behavior.

James Edward Gray II