class A
def numbers
[1,2,3,4]
end
def get_numbers(condition)
numbers = [3,5] if condition
numbers
end
end
a = A.new
a.get_numbers(true) # [3,5]
a.get_numbers(false) # nil
I expect it to return [1,2,3,4]
in the second case !
P.S. I am not looking for a solution(I can just have two different variable names to solve my issue), rather I am looking for an explanation for this behaviour, Does ruby creates the variable numbers
during runtime itself & initializes to nil
because of the if
condition ?