Thursday, April 9, 2009

Week 3: Rails Passion Course

  1. Week 3: Ruby Meta Programming (Topic covered: What is and why meta-programming?, Ruby language characteristics (that make it a great meta-programming language, Introspection, Object#send, Dynamic typing (and Duck Typing), missing_method, define_method.)
  2. * Week 3 Resources
    o Meta programming
    + Meta Programming - Extending Ruby for Fun and Profit presentation by Dave Thomas (Dec. 2007)
    + Screencasting on Ruby Meta programming by Dave Thomas (June, 2008)
    + Metaprogramming Ruby by Glenn Vanderburg
    + Metaprogramming from Wikipedia
    + Ola Bini's blogs on Meta programming
    o Duck typing
    + Duck typing from wikipedia.org
  3. Lab/Homework: ZIP File: o 5511_ruby_meta.zip (Unzip it in a directory of your choice and read lab document from /ruby_meta/index.html to proceed) (4/9/2009: done)
  4. * Presentation o PDF: 1 slide per page (OR) o OpenOffice file (4/9/2009: done)
  5. * Lab and homework (o Change Log) (p.1-29)
  6. Exercise 1? Introspection (p.2-11)
  7. (1.1) RubyMeta_Introspection_respond_to: Answer: http://pastie.org/442378 (p.2-8)
  8. (1.2) RubyMeta_Introspection_respond_to2: Answer: (p.8-9) ----Define Hello class
    ----Check if Hello object has a method called myhellomethod
    true
    ----Check if Hello object has a method called xyz
    false
  9. (1.3) RubyMeta_Introspection_instance_of: Answer: ----Exercise instance_of? and kind_of? methods among object instances
    true
    false (should be "B", not "A")
    true
    ----Exercise instance_of? and kind_of? methods for a class
    true
    true
    ----Display class information
    A
    Class
  10. (1.4) RubyMeta_Introspection_methods: Answer: http://pastie.org/442385 (p.10-11) Surprised by the lst 3 sections (no output).
  11. Exercise 2 (p.11-15)
  12. (2.1) RubyMeta_Object_send_hello: Answer: (p.12) Hello gentle readers
    Hello gentle readers
    Hello gentle readers
    Hello gentle readers
  13. (2.2) RubyMeta_Object_send_plus: Answer: (p.12-13) 5
    5
    5
    5
    6
    6
    6
    6
  14. (2.3) RubyMeta_Object_send_hello2: Answer: (p.13-14) Hello Boston!
    Hello Boston!
    Hello Boston!
    Hello Boston!
  15. (2.4) RubyMeta_Object_send_hello3: (p.14-15): Answer: http://pastie.org/442403
  16. Exercise 3: Dynamic Typing (Duck Typing) (p.15-16)
  17. (3.0) Article: The Perils of Duck Typing: http://beust.com/weblog/archives/000269.html
  18. (3.1) RubyMeta_DynamicTyping (p.15-16): Answer: ----Call quack method for each item of the birds array. Only Duck and Mallard should be quacking.
    Duck is quacking!
    Mallard is quacking!
  19. Exercise 4: Missing Methods (p.16-23)
  20. (4.1) RubyMeta_MethodMissing_Error (p.15-18) Answer: ----Call a method that does not exist in the Dummy class and expect NoMethodError exception.
    C:\cygwin\home\jasnow\RAILSPASSION\ruby_meta\samples\RubyMeta_MethodMissing_Error\lib\main.rb:13: undefined method `a_method_that_does_not_exist' for # (NoMethodError)
  21. (4.2) RubyMeta_MethodMissing_Called (p.18-19) Answer: http://pastie.org/442416
  22. (4.3) RubyMeta_MethodMissing_Finder (p.19-20) Answer: ----Call a method that does not exist in the Finder class and observe that the method_missing is called.
    find(Something) is called
    find(by_last_name) is called
    find(by_title) is called
  23. (4.4) RubyMeta_MethodMissing_RomanToInteger (p.20-21) Answer: ----Convert Roman to Integer using method_missing
    4
    23
    2000
  24. (4.5) RubyMeta_MethodMissing_ProxyPattern (p.21-23) Answer: http://pastie.org/442423
  25. Exercise 5: Define Method (p.23-
  26. (5.1) RubyMeta_DefineMethod (p.23) Answer: ----Call a method that is defined via define_method
    Sang Shin loves Young Shin
  27. (5.2) RubyMeta_DefineMethod2 (p.23-28) Answer: ----Get a method name from a user. Type something in the Output window and press Enter.
    abcd (I typed this)
    ----Define Love class which has define_method
    ----Create an instance of Love class
    ----Invoke a method that was dynamically defined
    abcd
    method is being invoked
    Daniel loves Yina

  28. (5.3) RubyMeta_DefineMethod3 (p.28-29) Answer: ----a.barney is equivalent to a.fred
    In Fred
    ----a.wilma is equivalent to a.wilma
    Charge it!
    ----a.create_method(:betty) { p self }
    ----a.betty
    #
  29. Online lab/Homework document (This is the same document you will find in the hands-on lab zip file)

No comments:

Post a Comment