[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

naked object macros

Keynan Pratt

11/5/2007 10:42:00 PM

I have

module A
module B
module ClassMethods

def a_method
end

end
end
end
==============================================================
I would like to be able to

class Klass
include A::B
a_method
end

==============================================================

the interpreter is complaining that a_method does not exist for
Klass:Class

any ideas?
--
Posted via http://www.ruby-....

2 Answers

Michael Guterl

11/5/2007 10:57:00 PM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

On 11/5/07, Keynan Pratt <keynan@howe.textdrive.com> wrote:
>
> I have
>
> module A
> module B
> module ClassMethods
>
> def a_method
> end
>
> end
> end
> end
> ==============================================================
> I would like to be able to
>
> class Klass
> include A::B
> a_method
> end
>
> ==============================================================
>
> the interpreter is complaining that a_method does not exist for
> Klass:Class
>
> any ideas?
> --
> Posted via http://www.ruby-....
>
>
Try this

module A
module B
module ClassMethods
def a_method
end
end
def self.included(base)
base.extend(ClassMethods)
end
end
end

class Klass
include A::B
a_method
end

Michael Guterl

Trans

11/6/2007 12:08:00 AM

0



On Nov 5, 5:41 pm, Keynan Pratt <key...@howe.textdrive.com> wrote:
> I have
>
> module A
> module B
> module ClassMethods
>
> def a_method
> end
>
> end
> end
> end
> ==============================================================
> I would like to be able to
>
> class Klass
> include A::B
> a_method
> end
>
> ==============================================================
>
> the interpreter is complaining that a_method does not exist for
> Klass:Class
>
> any ideas?

$ gem install facets

require 'facets/class_extension'

module A

module B

class_extension do

def a_method
end

end
end
end

T.