Created
November 19, 2012 19:31
-
-
Save sdeming/4113126 to your computer and use it in GitHub Desktop.
Totally Contrived Episode #1 - class << self
This file contains hidden or 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
class Foo | |
class << self | |
attr_accessor :a, :b | |
end | |
def self.register(args = {}) | |
args.each do |k,v| | |
self.send(:"#{k}=", v) | |
end | |
end | |
def self.moo | |
a * b | |
end | |
end | |
class FooLish < Foo | |
register :a => 7, :b => 6 | |
end | |
class FooNiture < Foo | |
register :a => 1, :b => 2 | |
end | |
puts FooLish.moo | |
puts FooNiture.moo | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment