[Ironruby-core] Forgetting MutableString

Peter Bacon Darwin bacondarwin at googlemail.com
Fri May 9 01:41:08 EDT 2008


This actually makes my problem worse!  Now there is no way of catching the
times when I accidentally return a CLR string rather than a MutableString.
It will only flag up when client code tries to call a MutableString method
on the CLR string.
Pete

-----Original Message-----
From: ironruby-core-bounces at rubyforge.org
[mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of John Lam
(IRONRUBY)
Sent: Thursday,08 May 08, 2008 17:23
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Forgetting MutableString

Peter Bacon Darwin:

> I keep forgetting to wrap up CLR strings in MutableStrings when
> returning strings retrieved from calls to .NET Framework library
> methods.

I finally understand what this is ... is this what you're looking for?

        public override bool Equals(object other) {
            if (other is MutableString)
                return Equals(other as MutableString);
            else if (other is string)
                return Equals(other as string);
            else
                return false;
        }

        public bool Equals(string other) {
            if (other == null) return false;
            if (_data.Length != other.Length) return false;

            for (int i = 0; i < _data.Length; ++i)
                if (_data[i] != other[i])
                    return false;

            return true;
        }

        public bool Equals(MutableString other) {
            if (ReferenceEquals(this, other)) return true;
            if (other == null) return false;
            if (_data.Length != other.Length) return false;

            for (int i = 0; i < _data.Length; ++i)
                if (_data[i] != other.Chars[i])
                    return false;

            return true;
        }

If so, it's coming in the next release.

Thanks,
-John

_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core



More information about the Ironruby-core mailing list