Created
July 18, 2011 04:13
-
-
Save prodis/1088527 to your computer and use it in GitHub Desktop.
Ruby Fundamental - Um pouco sobre classes (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 | |
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
d = Dog.new |
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 bark | |
puts "Au, au, au!" | |
end | |
def sleep | |
puts "Zzzzzzz..." | |
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
d = Dog.new | |
d.sleep # => Zzzzzzz... | |
d.bark # => Au, au, au! |
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 "Au, au, au!" | |
end | |
def sleep | |
puts "Zzzzzzz..." | |
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
d = 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
d = Dog.new | |
# => ArgumentError: wrong number of arguments (0 for 2) |
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 "Au, au, au!" | |
end | |
def sleep | |
puts "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" | |
pixel = Dog.new "Pixel", "Yorkshire" | |
puts snoopy # => Snoopy is a Beagle. | |
puts pixel # => Pixel is a 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
puts snoopy | |
puts snoopy.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment