I'm wondering why assignment with the ternary operator reacts strangely:
a = "foo"
=> "foo"
a = nil ? nil : a
=> "foo"
a
=> "foo"
but:
a = nil ? nil : a
=> "foo"
a = "bar" ? "bar" : a
=> "bar"
a
=> "bar"
and:
if a = nil
puts "should be nil"
end
=> nil
won't puts the string because a = nil will return nil thus false, although the assignment was successful.
Is that all behaving like intended?
a = (nil ? nil : a). Since nil is "falsey", you assign the previous value ofatoa, which is"foo".