Created
May 15, 2010 02:05
-
-
Save titanous/401937 to your computer and use it in GitHub Desktop.
Potential router DSL for Mailman
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
subject(/Ticket/).to(':user@example.com') do | |
User.find_by_identifier(params[:user]).add_ticket(message) | |
end |
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
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