Skip to content

Instantly share code, notes, and snippets.

@davidlee
Created March 13, 2010 07:50
Show Gist options
  • Save davidlee/331194 to your computer and use it in GitHub Desktop.
Save davidlee/331194 to your computer and use it in GitHub Desktop.
def ensure_argument list
list.each do |value, tests|
[tests].flatten.each do |test|
case test.to_s
when /^is_an?_(.*)$/
value.is_a? $1.classify.constantize
when /^is_(.*)$/
value.respond_to?($1) && value.send($1)
when /^(has|can)_(.*)/
value.respond_to? $2
end || raise(ArgumentError, "Expected #{value} to #{test}")
end
end
end
def debit(debitor, balance, descr)
ensure_argument debitor => [:has_account, :is_active],
balance => :is_a_bignum, descr => :is_a_string
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment