On 8/15/05, Joe Van Dyk <joevandyk / gmail.com> wrote:
> module JoeAccessors
>   class << self
>     def joe_accessor_method *args
>       args.each do |arg|
>         eval <<-src
>           def #{ arg }
>             @#{ arg }
>           end
>           def #{ arg }= value
>             @#{ arg } = value
>           end
>         src
>       end
>     end
>   end
> end
> 
> class Joe
>   include JoeAccessors
>   joe_accessor_method :arg1, :arg2
> end
> 

module JoeAccessors
  def joe_accessor_method *args
    args.each do |arg|
      eval <<-src
        class << self
          def #{ arg }
            @#{ arg }
          end
          def #{ arg }= value
            @#{ arg } = value
          end
        end
      src
    end
  end
end

class Joe
  extend JoeAccessors
  joe_accessor_method :arg1, :arg2
end

This seems to be where the problem is. The module method does not
become a class method by include. The other thing to note is that I
moved the class << self so it targets your final object (instance of
Class in this case). Otherwise, you will find that it will not find
you method.

However, I am not sure what else you are trying to accomplish by this
code... as a guess, the following works for me:

Joe.arg1 = 42
Joe.arg1 #=> 42

> > test.rb:21: undefined method `joe_accessor_method' for Joe:Class (NoMethodError)
> 
> *bangs head against desk*

Always wear a helmet when doing any meta-programming.  :)

Brian.