------=_NextPart_000_00F1_01C831B0.C43AC490
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

You might take a look at the metaid gem

Gem install metaid

It contains some of those meta classes - I use it for creating Activerecord
classes on the fly for data driven XML ingestion.

Jamie

-----Original Message-----
From: ruby-talk-admin / ruby-lang.org [mailto:ruby-talk-admin / ruby-lang.org]
On Behalf Of rbysamppi / gmail.com
Sent: Tuesday, November 27, 2007 9:35 PM
To: ruby-talk ML
Subject: Turning Dwemthy's Array into a mixin

As a beginner, I'm having trouble converting the metaprogramming in
Dwemthy's Array (http://poignantguide.net/dwemthy/) into a convenient
mixin that I can use for many classes. The trouble seems to be the
"def self." declarations, but I'm not too sure; in any
case, .metaclass and .traits don't seem to be mixing in. What should I
change?

Thanks in advance!

module Dwemthy

  def self.metaclass
    class << self; self; end
  end

  def self.traits(*given_traits)
    return @traits if given_traits.empty?

    attr_accessor(*given_traits)

    given_traits.each do |trait|
      metaclass.instance_eval do
        define_method(trait) do |trait_value|
          @traits ||= {}
          @traits[trait] = trait_value
        end
      end
    end

    class_eval do
      define_method(:initialize) do
        self.class.traits.each do |k, v|
          instance_variable_set("@#{k}", v)
        end
      end
    end
  end

end


------=_NextPart_000_00F1_01C831B0.C43AC490
Content-Type: application/x-pkcs7-signature;
	name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="smime.p7s"

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIYKjCCAlow
ggHDAgIBpTANBgkqhkiG9w0BAQQFADB1MQswCQYDVQQGEwJVUzEYMBYGA1UEChMPR1RFIENvcnBv
cmF0aW9uMScwJQYDVQQLEx5HVEUgQ3liZXJUcnVzdCBTb2x1dGlvbnMsIEluYy4xIzAhBgNVBAMT
GkdURSBDeWJlclRydXN0IEdsb2JhbCBSb290MB4XDTk4MDgxMzAwMjkwMFoXDTE4MDgxMzIzNTkw
MFowdTELMAkGA1UEB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