Skip to content

Instantly share code, notes, and snippets.

@tooky
Created November 21, 2012 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tooky/4124434 to your computer and use it in GitHub Desktop.
Save tooky/4124434 to your computer and use it in GitHub Desktop.
module Context
def the(key, value)
context[key] = value
end
def method_missing(method, *args, &block)
key = extract_key(method)
if key
context.fetch(key.to_sym)
else
super
end
end
private
def context
@context ||= {}
end
def extract_key(method)
method[/^the_(.+)/, 1]
end
end
World(Context)
@tooky
Copy link
Author

tooky commented Nov 21, 2012

the(:customer, create_customer(:name => 'Tom')
the(:customer).name #=> 'Tom'

@tooky
Copy link
Author

tooky commented Nov 21, 2012

Or rather...

the(:customer, create_customer(:name => 'Tom'))
the_customer.name #=> 'Tom'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment