Skip to content

Instantly share code, notes, and snippets.

@rosylilly
Created October 8, 2009 10:58
Show Gist options
  • Save rosylilly/204945 to your computer and use it in GitHub Desktop.
Save rosylilly/204945 to your computer and use it in GitHub Desktop.
理解不能
class Foo
@baz = 1
@@bar = 2
def self.baz; @baz; end
def self.baz=(n); @baz=n; end
def self.bar; @@bar; end
def self.bar=(n); @@bar=n; end
end
class Hoge < Foo
end
p Foo.baz # => 1
p Foo.bar # => 2
p Hoge.baz # => nil
p Hoge.bar # => 2
__foo__ = Foo.clone
Foo.baz = 2
Foo.bar = 1
p __foo__.baz # => 1
p __foo__.bar # => 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment