String Equality Operation

Hi There,

I’m doing a bit of playing around with IronRuby and ticking along ok.
One thing which I’m having difficulty with though is string equality
between a string that’s come from an external object.

Example:

mystring = $external.MyMethod
puts “mystring=#{mystring}.”

if mystring == ‘abcd’
puts “Match.”
else
puts "No match.
end

Output:

mystring=abcd.
No Match.

So I can get the value from my external method ok but it’s not macthing
up with the IronRuby string object.

Does anyone know whether this is something I’m doing wrong?

Regards,

Aaron

Found the answer for those that might come across this and are in the
same boat:

http://www.ruby-forum.com/topic/126197#new

Working Example:

mystring = $external.MyMethod.to_s
puts “mystring=#{mystring}.”

if mystring == ‘abcd’
puts “Match.”
else
puts "No match.
end

Output:

mystring=abcd.
Match.

Regards,

Aaron

Aaron C.:

mystring = $external.MyMethod.to_s
puts “mystring=#{mystring}.”

if mystring == ‘abcd’
puts “Match.”
else
puts "No match.
end

If you look at the class of each of your strings you’ll find that they
are currently different types. mystring should be a ClrString and ‘abcd’
is a String. If you do mystring.to_s == ‘abcd’ it should return true.

We’re working on a plan to unify all string types and do lazy
conversions as necessary. We’re slammed doing MIX work so that won’t
start happening until we’re locked down for MIX (at least a couple of
weeks or so).

Thanks
-John