Skip to content

Instantly share code, notes, and snippets.

@prodis
Created Jul 18, 2011
Embed
What would you like to do?
Ruby Fundamental - Um pouco sobre classes (parte II)
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
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