Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby Fundamental - Acessores e modificadores de atributos (parte II)
class Dog
attr_accessor :name, :breed
def initialize(name, breed)
@name, @breed = name, breed
end
# Os demais métodos foram omitidos
end
dog = Dog.new "Snoopy", "Beagle"
dog.name = "Pixel"
dog.breed = "Yorkshire"
dog.name # => Pixel
dog.breed # => Yorkshire
class Dog
attr_accessor :name, :breed
def initialize(name, breed)
@name, @breed = name, breed
end
def bark
puts "#{@name}: Au, au, au!"
end
def sleep
puts "#{@name}: Zzzzzzz..."
end
def to_s
"#{@name} is a #{@breed}."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment