On 03/10/05, itsme213 <itsme213 / hotmail.com> wrote:
> Hmmm. Here is what I want:
>
> module M
>   # magic for #foo, #bar
> end
>
> class C
>   include M
>   # should do the equivalent of:
>     # def C.foo(n); @foo = n; end
>     # def bar; self.class.iv_get "@foo"; end
>   foo 55 #
> end
>
> C.new.bar #=> 55
>
> I'm having trouble getting this to work. Purely my limited prowess, I am
> sure ...

Maybe that this is not the most elegant method, but heres what I came up with

module M
  def self.append_features(klass)
    class << klass

      def foo= n
	@foo = n
      end

    end

    super
  end

  def foo
    self.class.instance_variable_get "@foo"
  end
end

class C
  include M
  self.foo = 55
end

p C.new.foo

regards,

Brian


--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/