From c4cbf576e33c12a5b0c64e0b94dd9736c27d6bb6 Mon Sep 17 00:00:00 2001 From: ashbb Date: Thu, 4 Jun 2009 01:10:58 +0900 Subject: [PATCH] Added new sections: Interesting Articles and Small Snippets --- README.md | 15 ++++++++++++++- snippets/ss001.md | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 snippets/ss001.md diff --git a/README.md b/README.md index 41412eb..df62bd0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Ruby Metaprogramming Study Note =============================== I'm now taking a sniff of Ruby Metaprogramming. This is my tiny Study Note. :) -May 23th, 2009 by ashbb (Satoshi Asakawa) +Jun 3rd, 2009 by ashbb (Satoshi Asakawa) Videos @@ -42,6 +42,19 @@ Sample Apps Very simple Ruby DSL on Shoes. +Interesting Articles +-------------------- +- [Seeing Metaclasses Clearly](http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html) +- [Extending your include knowledge of Ruby](http://macournoyer.wordpress.com/2007/07/06/extending-your-include-knowledge-of-ruby/) +- [Using methodmissing and respondto? to create dynamic methods](http://technicalpickles.com/posts/using-method_missing-and-respond_to-to-create-dynamic-methods) +- [Ola Bini's blogs on Meta programming](http://ola-bini.blogspot.com/search/label/metaprogramming) + + +Small Snippets +-------------- +- [ss001](http://github.com/ashbb/ruby_metaprogramming_study_note/tree/master/snippets/ss001.md): nested def keyword + + To do list ---------- - create more sample codes diff --git a/snippets/ss001.md b/snippets/ss001.md new file mode 100644 index 0000000..43e0571 --- /dev/null +++ b/snippets/ss001.md @@ -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) \ No newline at end of file