I don't believe it would matter in the case of a String. But it is
important to understand the difference. == compares value. eql? compares
value and type. In the case of ints versus floats for example 1==1.0 is
true, but 1.eql?(1.0) is false.
For some classes though, you will see that .eql? is really just syntactic
sugar sending to == anyway...
···
On 8/16/06, Brad Tilley <rtilley@vt.edu> wrote:
> b = 'brad'
>
> if 'bradsdhsh' == b
> puts 'equal'
> else
> puts 'not equal'
> end
>
> Or, as a one liner
>
> puts 'bradsdhsh' == b ? 'equal' : 'not equal'
if 'bradsdhsh' == b
puts 'equal'
else
puts 'not equal'
end
Or, as a one liner
puts 'bradsdhsh' == b ? 'equal' : 'not equal'
This is prefered over the String.eql? method?
I prefer it and it seems most others, too. Looks better - and note that it's not like in Java where there is a significant difference between == and equals().