Esempio n. 1
0
        public static long ToLong(NetRuby ruby, object o)
        {
            if (o == null)
            {
                throw new eTypeError("no implicit conversion from nil");
            }
            if (o is int)
            {
                return((long)(int)o);
            }
            if (o is uint)
            {
                return((long)(uint)o);
            }
            if (o is long)
            {
                return((long)o);
            }
            if (o is RNumeric)
            {
                return(((RNumeric)o).ToLong());
            }
            if (o is string || o is RString)
            {
                throw new eTypeError("no implicit conversion from string");
            }
            if (o is bool || o is RBool)
            {
                throw new eTypeError("no implicit conversion from boolean");
            }
            RFixnum f = (RFixnum)ruby.ConvertType(o, typeof(RFixnum), "Integer", "to_int");

            return((long)f.ToLong());
        }
Esempio n. 2
0
        static internal new void Init(NetRuby rb)
        {
            RClass fix = rb.DefineClass("Fixnum", rb.cInteger);

            rb.cFixnum = fix;
            RFixnum o = new RFixnum(rb);

            rb.oFixnum  = o;
            rb.oFixZero = new RFixnum(rb, 0);
            fix.DefineMethod("to_f", new RMethod(o.ruby_to_f), 0);

            fix.DefineMethod("to_c", new RMethod(o.ruby_to_c), 0);

            fix.DefineMethod("==", new RMethod(fix_equal), 1);
        }
Esempio n. 3
0
        static internal new void Init(NetRuby rb)
        {
            RClass fix = rb.DefineClass("Fixnum", rb.cInteger);
            rb.cFixnum = fix;
            RFixnum o = new RFixnum(rb);
            rb.oFixnum = o;
            rb.oFixZero = new RFixnum(rb, 0);
            fix.DefineMethod("to_f", new RMethod(o.ruby_to_f), 0);

            fix.DefineMethod("to_c", new RMethod(o.ruby_to_c), 0);
        
            fix.DefineMethod("==", new RMethod(fix_equal), 1);
        }