Skip to content

Instantly share code, notes, and snippets.

@jmeridth
Created March 18, 2010 01:51
Show Gist options
  • Save jmeridth/335962 to your computer and use it in GitHub Desktop.
Save jmeridth/335962 to your computer and use it in GitHub Desktop.
ruby object model class variables
@@test = 20
class A
@@a = 1
def self.a
@@a
end
def hello
puts "hello from A"
end
end
class B < A
@@a = 22
def hello
puts "hello from B"
end
end
puts @@test
a = A.new
a.hello
puts A.a
b = B.new
b.hello
puts B.a
~ > ruby test.rb
20
hello from A
22
hello from B
22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment