Created
July 18, 2011 04:15
-
-
Save prodis/1088530 to your computer and use it in GitHub Desktop.
Ruby Fundamental - Um pouco sobre classes (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 | |
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
snoopy = Dog.new "Snoopy", "Beagle" | |
snoopy.sleep # => Snoopy: Zzzzzzz... | |
snoopy.bark # => Snoopy: Au, au, au! | |
snoopy.to_s # => Snoopy is a Beagle. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment