Skip to content

Instantly share code, notes, and snippets.

@nathan-appere
Last active August 29, 2015 13:56
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 nathan-appere/9338088 to your computer and use it in GitHub Desktop.
Save nathan-appere/9338088 to your computer and use it in GitHub Desktop.
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