Created
April 7, 2011 14:46
-
-
Save albertoperdomo/907903 to your computer and use it in GitHub Desktop.
#scotruby exercise with extend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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