[Note: parts of this message were removed to make it a legal post.]
Thank you very much Rick. Using:
x = '-' if x.nil?
I've x = Null again..
x should not be Null at this point. First, Null doesn't exist, in Ruby it is
nil. Second, if you are using nil, then this should do what you want
x = nil
x = '-' if x.nil?
x # => "-"
x = 'abc'
x = '-' if x.nil?
x # => "abc"
It seems works with
if (x.to_s =~ /Null/)
x = '-'
end
but I don't think is the best way to write it
That probably isn't doing what you think / want. Since Null should be nil,
the only way that should match is if your class somehow returns a string
with 'Null' in it. That seems pretty unlikely.
I think Rick's answer is probably what you are looking for, but if an empty
string evaluates to false in php, then you will need to add the condition
for that, ie
x = '-' if !x || x.empty?
This assumes that x is expected to be a string, or nil.
You should look at your code and make switch out your 'Null' with 'nil' ,
and if this hasn't solved your issue, perhaps explain what you are trying to
do, ie give a series of different inputs, and what you want it to do to
them.