Skip to content

Instantly share code, notes, and snippets.

@titanous
Created May 15, 2010 02:05
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 titanous/401937 to your computer and use it in GitHub Desktop.
Save titanous/401937 to your computer and use it in GitHub Desktop.
Potential router DSL for Mailman
subject(/Ticket/).to(':user@example.com') do
User.find_by_identifier(params[:user]).add_ticket(message)
end
class Chainable
%w{foo bar baz}.each do |method|
class_eval <<-EOM # class_eval because define_method can't take named blocks in 1.8
def #{method}(arg, &block)
@#{method} = arg
if block_given?
@block = block
true
else
self
end
end
EOM
end
def test_helper
'I am a helper in Chainable'
end
def eval_block
instance_eval(&@block)
end
end
c = Chainable.new
c.foo('chunky').bar('bacon') { test_helper }
c.instance_variable_get('@foo') #=> "chunky"
c.instance_variable_get('@bar') #=> "bacon"
c.eval_block #=> "I am a helper in Chainable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment