Ara.T.Howard wrote:

> what you can't do, however, is to define a class method in a module and then
> somehow 'get it back' to inject it into the including class at runtime (well
> you could but it'd be very ugly).  i've found this approach to be quite simple
> and almost guaranteed to make sense to any developer that ever programmed an
> object-oriented language instantly - even if they don't understand the
> included method totally:
>
>      harp:~ > cat b.rb
>      module JoeAccessors
>
>        module ClassMethods
>          def joe_accessor_method *args
>            args.each do |arg|
>              module_eval <<-src
>                def #{ arg }
>                  @#{ arg }
>                end
>                def #{ arg }= value
>                  @#{ arg } = value
>                end
>              src
>            end
>          end
>        end
>
>        module InstanceMethods
>          # put em here
>        end

You can just put the instance methods where they normally go. No
InstanceMethods module needed.

>        def self::included other
>          other.extend ClassMethods
>          other.module_eval{ include InstanceMethods }
>        end

Then cahnge the above to:

         extend ClassMethods

         def self::included other
           other.extend ClassMethods
         end

> it's just a tiny bit clunky - but it makes it totally clear which methods are
> which without any doccumentation or understanding of 'class << self' etc.

A little less clunky.
 
T.