I want to use an equivalent of Oracle’s nvl() function in Ruby. Is there a built in function or do I have to write one myself?
Edit:
I am using it to rewrite some sql to ruby:
INSERT INTO my_table (id, val)
VALUES (1, nvl(my_variable,'DEFAULT'));
becomes
plsql.my_table.insert {:id => 1, :val => ???my_variable???}
You could use Conditional assignment
Operator
||=is a shorthand form of the expressionSome tests
And yes, If you don’t want false to be match, you could use
if x.nil?as Nick Lewis mentionedEdit:
would be
where x is the variable name to set in :val, ‘DEFAULT’ will be insert into db, when x is nil or false
If you only want nil to ‘DEFAULT’, then use following way