Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class A
@options = {}
class << self
def inherited(subclass)
subclass.options = {}
end
attr_accessor :options
[:x].each do |name|
define_method(name) do |value|
@options[name] = value
end
end
end
def print
puts "#{ self.class.name } #{ self.class.options[:x] }"
end
x 1
end
class B < A
x 3
end
A.new.print
B.new.print
A.new.print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.