Created
December 3, 2010 14:47
-
-
Save jacegu/727047 to your computer and use it in GitHub Desktop.
A little example about open Classes in Ruby
This file contains hidden or 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 'guau' | |
end | |
end | |
def try_my_dog | |
dog = Dog.new | |
dog.bark | |
begin | |
dog.purr | |
rescue NoMethodError | |
puts "dog doesn't have a method called 'purr'" | |
end | |
end | |
try_my_dog | |
class Dog | |
def purr | |
puts 'purr, purr, purr' | |
end | |
end | |
try_my_dog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment