Created
August 9, 2014 00:32
-
-
Save carlqt/c22769df9c441994813e to your computer and use it in GitHub Desktop.
Ruby global scoping
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 Animal | |
def dog | |
"I'm a dog" | |
end | |
def cat | |
"I'm a cat" | |
end | |
def bird | |
"I'm a bird" | |
end | |
end | |
# I want something like this to happend: | |
animal = Animal.new() do | |
dog # => "I'm a dog" | |
cat # => "I'm a cat" | |
bird # => "I'm a bird" | |
end |
What it basically does is, it will run that block on the instance you just created (Animal.new)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this to your animal class: