[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Modules and foo

curtis.schofield@gmail.com

10/24/2006 12:44:00 AM

I have some questions about some things that i don't understand..
here is some code fragments

I have two questions.

One.. is there a better way to inherit between modules
that i don't know about?

Two.. why, when a method is called in module Bar does the Module
InstanceMethods in Bar not get included?


module Blah
def self.append_features(base)
super
base.extend ClassMethods
end
module InstanceMethods
def visible

end
end
module ClassMethods

def _do_other

class_eval <<-EOV
include InstanceMethods
EOV

end

def do_blah
"blah"
end
end
end

module Bar
def self.append_features(base)
super
base.extend ClassMethod
#
# This is ugly
# How do i avoid this?
#
base.extend Blah::ClassMethods
end
module InstanceMethods
def hidden

end
end
module ClassMethods
def do_bar
do_blah
#
#
# When i do this , i don't get the InstanceMethods of Bar, just Blah
#
_do_other
end
end

end

2 Answers

Nate Wiger

10/24/2006 5:49:00 PM

0

Curtis Schofield wrote:
> Two.. why, when a method is called in module Bar does the Module
> InstanceMethods in Bar not get included?
>
> module Blah
> def self.append_features(base)
> super
> base.extend ClassMethods
> end
> module InstanceMethods
> def visible
>
> end
> end

Do you mean "class InstanceMethods"? Modules are collections, often of
classes.

-Nate

curtis.schofield@gmail.com

10/24/2006 9:36:00 PM

0


> Curtis Schofield wrote:
>> Two.. why, when a method is called in module Bar does the Module
>> InstanceMethods in Bar not get included?
>> module Blah
>> def self.append_features(base)
>> super
>> base.extend ClassMethods
>> end
>> module InstanceMethods
>> def visible
>> end
>> end
>
> Do you mean "class InstanceMethods"? Modules are collections, often
> of classes.


I'm following a pattern that Rails uses for the "Acts As" code.

I don't want to muddle with the inheritance tree, i just want to mix-
in methods.