Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. def case_clause(var: nil, statements:, default: nil)
  2. c_result = " CASE %{var_input}\n" % {var_input: var}
  3. c_when_then = " WHEN %{when_input} THEN %{then_input} "
  4. c_else = " ELSE %{else_input} END\n"
  5. c_default = " DEFAULT %{default} END\n"
  6. c_end = " END\n"
  7.  
  8. statements.each do |condition, t, f|
  9. c_result << (c_when_then % {when_input: condition, then_input: t}) << (f.present? ? (c_else % {else_input: f}) : c_end)
  10. end
  11.  
  12. c_result << c_default if default.present?
  13. c_result << c_end
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement