Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new sections: Interesting Articles and Small Snippets
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
ss001: nested def keyword | ||
------------------------- | ||
|
||
# small snippet 001 | ||
class Dog | ||
def say | ||
def cry | ||
def bark | ||
puts 'Wooo!' | ||
end | ||
end | ||
end | ||
end | ||
|
||
d = Dog.new | ||
p Dog.instance_methods(false) #=> ["say"] | ||
d.say | ||
p Dog.instance_methods(false) #=> ["say", "cry"] | ||
d.cry | ||
p Dog.instance_methods(false) #=> ["say", "bark", "cry"] | ||
d.bark #=> Wooo! | ||
|
||
|
||
The method is actually created dinamically. | ||
The method `cry` is not created until the method `say` is executed. | ||
|
||
For more information: [Dynamically created methods in Ruby](http://ola-bini.blogspot.com/2008/05/dynamically-created-methods-in-ruby.html) |