Skip to content

Instantly share code, notes, and snippets.

@karapetyan
Forked from comatory/instance.rb
Last active September 24, 2015 09:07
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 karapetyan/70d82b42906f788ae1fb to your computer and use it in GitHub Desktop.
Save karapetyan/70d82b42906f788ae1fb to your computer and use it in GitHub Desktop.
class Customer
attr_reader :name
def initialize(name)
@name = name # @name instance variable, cause it's created when instance initialized
end
@class_variable = 'hello' #=> also class variable :P
def self.class_variable
@class_variable
end
end
peter = Customer.new("Peter")
john = Customer.new("John")
puts peter.name
puts john.name
puts peter.class.class_variable # will return a same value!
puts john.class.class_variable # will return a same value!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment