Skip to content

Latest commit

 

History

History
94 lines (48 loc) · 2.29 KB

_outline.html.md

File metadata and controls

94 lines (48 loc) · 2.29 KB

From Rails Recipes

From rails recipe, #1: To model rich many-to-many relationships in Rails, use join models to leverage

Active Record's has_many :through() macro.

Macros and the Ruby metaprogramming model

Various approaches

  • Substitution

  • REXX

  • M4

  • CPP - Allows (eponymous) preprocessing of C and C++ code relieving the burden on compiler and linker. CPP trades compile time substitution for run time elimination of function calls. Example: min and max are may be implemented as macros in C and C++. CPP can be used for general-purpose string substitution in any text file; it is not limited to C programming language source files.

  • TeX - Textual replacement eliminates commonly patterns, and allows parameterization of structurally repetitive but non-identical construction.

  • Gema

  • Lua macros

  • Rewriting - substitution - syntax-based macros

  • Macros which operate on parse trees rather than strings.

  • Parse trees as inputs, parse trees as outputs.

  • Delayed evaluation; call-by-name.

  • Methods which run at parse time, instead of at run time.

  • Because macro are methods, they are Turing complete and have the full power of Ruby methods.

  • Because macros are evaluated at parse time, they do not have access to the "full" Ruby system.

  • Helps keep things DRY which isn't methods, classes etc.

Important background

Ruby macro implementations

Caleb

Reg Braithewaite

Ola Bini

Coding horror