Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created November 29, 2015 11:53
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 anonymous/3844245526602050cfa0 to your computer and use it in GitHub Desktop.
Save anonymous/3844245526602050cfa0 to your computer and use it in GitHub Desktop.
class Foo
@foo_count = 0 <---- instance variable
def self.increment_counter <---- class method
@foo_count += 1
end
def self.current_count
@foo_count
end
end
class Bar < Foo
@foo_count = 100
end
Foo.increment_counter <---- how class method can access to instance variable?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment