Skip to content

Instantly share code, notes, and snippets.

@shime
Forked from pankoholic/dog_@.rb
Created July 1, 2012 21: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 shime/3029643 to your computer and use it in GitHub Desktop.
Save shime/3029643 to your computer and use it in GitHub Desktop.
difference between using @ over self
class Dog
def age
@age
end
def initialize(age)
@age = age
end
end
d = Dog.new(8)
puts d.age
class Dog
attr_reader :age
def initialize(age)
@age = age
end
end
d = Dog.new(8)
puts d.age
class Dog
def age
@age
end
def age= age
@age = age
end
def initialize(age)
self.age = age
end
end
d = Dog.new(8)
puts d.age
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment