Created
July 18, 2011 16:37
-
-
Save prodis/1090019 to your computer and use it in GitHub Desktop.
Ruby Fundamental - Acessores e modificadores de atributos (parte I)
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 | |
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 |
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" |
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 | |
def initialize(name, breed) | |
@name, @breed = name, breed | |
end | |
def name | |
@name | |
end | |
def breed | |
@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 # => Snoopy | |
dog.breed # => Beagle |
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 | |
def initialize(name, breed) | |
@name, @breed = name, breed | |
end | |
def name | |
@name | |
end | |
def breed | |
@breed | |
end | |
def name=(value) | |
@name = value | |
end | |
def breed=(value) | |
@breed = value | |
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") |
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" |
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" |
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.name=("Pixel") |
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.name = "Pixel" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment