I noticed a strange behavior with Ruby local variables in the code below. It seems that Ruby runs into the false part and sets params
to nil. The code in irb is below:
2.1.2 :001 > def params
2.1.2 :002?> {a:1}
2.1.2 :003?> end
2.1.2 :014 > def go1!
2.1.2 :015?> p params
2.1.2 :016?> if false
2.1.2 :017?> params = 1
2.1.2 :018?> end
2.1.2 :019?> p params
2.1.2 :020?> end
=> :go1!
2.1.2 :021 > go1!
{:a=>1}
nil
=> nil
Can anyone explain this?