Skip to content

Instantly share code, notes, and snippets.

@albertoperdomo
Created April 7, 2011 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertoperdomo/907903 to your computer and use it in GitHub Desktop.
Save albertoperdomo/907903 to your computer and use it in GitHub Desktop.
#scotruby exercise with extend
module MyAttributes
@@attributes = []
def my_accessor(field)
@@attributes << field
attr_accessor(field)
end
def my_attributes
@@attributes
end
end
class MyClass
extend MyAttributes
my_accessor :field1
my_accessor :field2
end
class SomeOtherClass
extend MyAttributes
my_accessor :field3
my_accessor :field4
end
m = MyClass.new
m.field1 = 99
n = SomeOtherClass
puts m
puts m.field1
p MyClass.my_attributes
p SomeOtherClass.my_attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment