Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def case_clause(var: nil, statements:, default: nil)
- c_result = " CASE %{var_input}\n" % {var_input: var}
- c_when_then = " WHEN %{when_input} THEN %{then_input} "
- c_else = " ELSE %{else_input} END\n"
- c_default = " DEFAULT %{default} END\n"
- c_end = " END\n"
- statements.each do |condition, t, f|
- c_result << (c_when_then % {when_input: condition, then_input: t}) << (f.present? ? (c_else % {else_input: f}) : c_end)
- end
- c_result << c_default if default.present?
- c_result << c_end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement