Skip to content

Instantly share code, notes, and snippets.

@deathbob
Forked from ianterrell/gist:1102751
Created July 24, 2011 15:59
Show Gist options
  • Save deathbob/1102763 to your computer and use it in GitHub Desktop.
Save deathbob/1102763 to your computer and use it in GitHub Desktop.
Meta module madness
module Foo
def bar
@bar ||= self.snakes
end
def bar=(val)
@bar = val
end
end
class Baz
def self.snakes
[:cobra]
end
extend Foo
end
class Boom < Baz
@bar = [:copperhead]
end
class Bam < Baz
def self.snakes
[:mamba]
end
end
Baz.bar # [:cobra]
Boom.bar # [:copperhead]
Bam.bar # [:mamba]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment