Skip to content

@albertoperdomo /extend.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#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
Something went wrong with that request. Please try again.