Skip to content

Instantly share code, notes, and snippets.

@comatory
Forked from karapetyan/instance.rb
Last active September 24, 2015 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save comatory/1ec93c5791052e3ea5e7 to your computer and use it in GitHub Desktop.
Save comatory/1ec93c5791052e3ea5e7 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'
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
puts john.class.class_variable
john.class.class_variable = 'bye' # this will give you an error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment