Forum: Ruby naked object macros

Posted by Keynan Pratt (keynan)
on 2007-11-05 23:41
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 by Michael Guterl (Guest)
on 2007-11-05 23:59
(Received via mailing list)
On 11/5/07, Keynan Pratt <keynan@howe.textdrive.com> wrote:
>   end
> ==============================================================
>
> the interpreter is complaining that a_method does not exist for
> Klass:Class
>
> any ideas?
> --
> Posted via http://www.ruby-forum.com/.
>
>
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
Posted by Trans (Guest)
on 2007-11-06 01:09
(Received via mailing list)
On Nov 5, 5:41 pm, Keynan Pratt <key...@howe.textdrive.com> wrote:
>  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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.