Created
March 16, 2014 14:33
-
-
Save sunloverz/9584123 to your computer and use it in GitHub Desktop.
Ruby metaprogramming list of spells (ie design patterns)
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
Argument Array | |
Collapse a list of arguments into an array. | |
Around Alias | |
Call the previous, aliased version of a method from a redefined method. | |
Blank Slate | |
Remove methods from an object to turn them into Ghost Methods. | |
Class Extension | |
Define class methods by mixing a module into a class's eigenclass. | |
Class Extension Mixin | |
Enable a module to extend is include through a Hook Method. | |
Class Instance Variable | |
Store class-level state in an instance variable of the Class object. | |
Class Macro | |
Use a class method in a class definition. | |
Clean Room | |
Use an object as an environment in which to evaluate a block. | |
Code Processor | |
Process a String of Code from an external source. | |
Context Probe | |
Execute a block to access information in an object's context. | |
Deferred Evaluation | |
Fore a piece of code and its context in a proc or lambda for evaluation later. | |
Dynamic Dispatch | |
Decide which method to call at runtime. | |
Dynamic Method | |
Decide how to define a method at runtime. | |
Dynamic Proxy | |
Forwad to another object any messages that don't match a method. | |
Flat Scope | |
Use a closure to share variable between two scopes. | |
Ghost Method | |
Respond to a message that doesn't have an associated method. | |
Hook Method | |
Override a method to intercept object model events. | |
Kernal Method | |
Define a method in module Kernal to make the method available to all objects. | |
Lazy Instance Variable | |
Wait until the first access to initialize an instance variable. | |
Mimic Method | |
Disguise a method as another language contruct. | |
Monkey patch | |
Change the features of an existing class. | |
Named Arguments | |
Collect method arguments into a hash to identify them by name. | |
Namespace | |
Define constants within a module to avoid name clashes. | |
Nil Guard | |
Override a reference to nil with an || | |
Object Extension | |
Define Singleton Methods by mixing a module into an object's eigenclass. | |
Open Class | |
Modify an existing class. | |
Pattern Dispatch | |
Select which methods to call based on their names. | |
Sandbox | |
Execute untrusted code in a safe environment. | |
Scope Gate | |
Isolate a scope with the class, module, or def keyword. | |
Shared Scope | |
Share variables among multiple contexts in the same Flat Scope. | |
Singleton Method | |
Define a method on a single object | |
String of Code | |
Evaluate a string of Ruby code. | |
Symbol to Proc | |
Convert a symbo to a block that calls a single method. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment