0
I wonder if there is a more ruby-like way to assign the return of a method to a variable only if it is not nil.
An example code of how it would work in, say, an ugly way.
def meu_metodo(valor)
valor if valor.even?
end
variavel = nil
[2, 3, 4, 5, 6].each do |valor|
tmp = meu_metodo(valor)
variavel = tmp unless tmp.nil?
puts variavel
end
Color in a temporary variable to then perform the test, there is some way to perform this test already in the assignment?
Thank you.