Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Popular
Metaprogramming
Patterns in Ruby

Glenn Espinosa
Seeing Metaprogramming And Lambda
Function Patterns in Ruby

By Lukas Nimmo
“Ruby is beautiful so our
DSLs should be beautiful
(yet extremely powerful)”
Metaprogramming
techniques for beautiful DSLs
• Configuration options
• Situational language
• Declarative DSLs
• Flexible ...
1. Configuration Options
Goal: Provide global config options for a library
Solution: User can specify config options and it will always
configure the Singleton. Using a block makes configuration
expli...
2. Situational language
Goal: Offer situational language = Flexible interface that
relies on the same implementation
Solution: Alias methods for singular & plural implementations,
also consider synonyms (RSpec uses this a lot)
3. Declarative DSL’s
Goal: Declarative DSL's for setting up classes in your
domain with common functionality.
4. Flexible Interfaces
Goal: Allow many entries around the same structure.
Reduce scoping for common functionality.
Reduce redundancy for
your users
Metaprogramming patterns
Metaprogramming patterns
Metaprogramming patterns
Upcoming SlideShare
Loading in …5
×

Metaprogramming patterns

popular ruby metaprogramming patterns

  • Be the first to comment

  • Be the first to like this

Metaprogramming patterns

  1. 1. Popular Metaprogramming Patterns in Ruby Glenn Espinosa
  2. 2. Seeing Metaprogramming And Lambda Function Patterns in Ruby By Lukas Nimmo
  3. 3. “Ruby is beautiful so our DSLs should be beautiful (yet extremely powerful)”
  4. 4. Metaprogramming techniques for beautiful DSLs • Configuration options • Situational language • Declarative DSLs • Flexible interfaces
  5. 5. 1. Configuration Options Goal: Provide global config options for a library
  6. 6. Solution: User can specify config options and it will always configure the Singleton. Using a block makes configuration explicit. @gpespn
  7. 7. 2. Situational language Goal: Offer situational language = Flexible interface that relies on the same implementation
  8. 8. Solution: Alias methods for singular & plural implementations, also consider synonyms (RSpec uses this a lot)
  9. 9. 3. Declarative DSL’s Goal: Declarative DSL's for setting up classes in your domain with common functionality.
  10. 10. 4. Flexible Interfaces Goal: Allow many entries around the same structure. Reduce scoping for common functionality.
  11. 11. Reduce redundancy for your users

×