Ejemplo n.º 1
0
        /// <summary>
        /// Try to compare the lhs and rhs. Throws and exception if comparison returns null. Returns -1/0/+1 otherwise.
        /// </summary>
        public static int Compare(ComparisonStorage /*!*/ comparisonStorage, object lhs, object rhs)
        {
            var compare = comparisonStorage.CompareSite;

            var result = compare.Target(compare, lhs, rhs);

            if (result != null)
            {
                return(Protocols.ConvertCompareResult(comparisonStorage, result));
            }
            else
            {
                throw RubyExceptions.MakeComparisonError(comparisonStorage.Context, lhs, rhs);
            }
        }
Ejemplo n.º 2
0
        public static int ConvertCompareResult(ComparisonStorage /*!*/ comparisonStorage, object /*!*/ result)
        {
            Debug.Assert(result != null);

            var greaterThanSite = comparisonStorage.GreaterThanSite;

            if (RubyOps.IsTrue(greaterThanSite.Target(greaterThanSite, result, 0)))
            {
                return(1);
            }

            var lessThanSite = comparisonStorage.LessThanSite;

            if (RubyOps.IsTrue(lessThanSite.Target(lessThanSite, result, 0)))
            {
                return(-1);
            }

            return(0);
        }