Created
July 18, 2011 16:38
-
-
Save prodis/1090022 to your computer and use it in GitHub Desktop.
Ruby Fundamental - Acessores e modificadores de atributos (parte II)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog | |
attr_accessor :name, :breed | |
def initialize(name, breed) | |
@name, @breed = name, breed | |
end | |
# Os demais métodos foram omitidos | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dog = Dog.new "Snoopy", "Beagle" | |
dog.name = "Pixel" | |
dog.breed = "Yorkshire" | |
dog.name # => Pixel | |
dog.breed # => Yorkshire |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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