Ruby chaining methods with if-statement -
this question has answer here:
- one line if statement in ruby 1 answer
i have following:
def method(integer) = 3+integer += 10 if "one"<"another" end
can write in 1 line somehow chaining methods?
something a = 3+f += 10 if "one"<"another"
?
since and
or &&
both use short-circuit evaluation, use:
(a = 3+integer) , ("one"<"another") , (a += 10)
it says in 'using “and” , “or” in ruby':
and useful chaining related operations until 1 of them returns nil or false
another way of thinking and reversed if statement modifier
Comments
Post a Comment