Example #1
0
        public void Initialize(RubyContext /*!*/ context, object begin, object end, bool excludeEnd)
        {
            if (_initialized)
            {
                throw RubyExceptions.CreateNameError("`initialize' called twice");
            }

            // Range tests whether the items can be compared, and uses that to determine if the range is valid
            // Only a non-existent <=> method or a result of nil seems to trigger the exception.
            object compareResult = null;

            try {
                compareResult = RubySites.Compare(context, begin, end);
            } catch (Exception) {
            }
            if (compareResult == null)
            {
                throw RubyExceptions.CreateArgumentError("bad value for range");
            }

            _begin       = begin;
            _end         = end;
            _excludeEnd  = excludeEnd;
            _initialized = true;
        }
Example #2
0
        public static object Equal(RubyContext /*!*/ context, object self, object other)
        {
            // Short circuit long winded comparison if the objects are actually the same.
            if (self == other)
            {
                return(true);
            }

            // TODO: handle exceptions thrown from Compare()
            // Compare may return null
            object result = RubySites.Compare(context, self, other);

            if (result is int)
            {
                return((int)result == 0);
            }
            else
            {
                return(null);
            }
        }