Skip to content

Instantly share code, notes, and snippets.

@taq
Created May 9, 2018 11:21
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 taq/828311b6c998fafce9c2c9cc90efb2a5 to your computer and use it in GitHub Desktop.
Save taq/828311b6c998fafce9c2c9cc90efb2a5 to your computer and use it in GitHub Desktop.
Ruby class variable
class Foo
class << self
attr_reader :ivar
end
@ivar = 'Hello!'
end
class Bar < Foo
@ivar = 'World'
end
class Baz < Foo
@ivar = 'Underworld'
end
puts Baz.ivar
puts Bar.ivar
puts Foo.ivar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment