예제 #1
0
파일: Numeric.cs 프로젝트: retahc/old-code
        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());
        }
예제 #2
0
파일: Numeric.cs 프로젝트: retahc/old-code
        // as rb_Float
        static public RFloat Float(NetRuby rb, object o)
        {
            if (o == null || o == rb.oNil)
            {
                return(new RFloat(rb, 0.0));
            }
            if (o is int)
            {
                return(new RFloat(rb, (double)(int)o));
            }
            if (o is long)
            {
                return(new RFloat(rb, (double)(long)o));
            }
            if (o is double)
            {
                return(new RFloat(rb, (double)o));
            }
            if (o is RFloat)
            {
                return((RFloat)o);
            }
            if (o is RBignum)
            {
                return(new RFloat(rb, ((RBignum)o).Big2Dbl()));
            }
            string s = null;

            if (o is string)
            {
                s = (string)o;
            }
            else if (o is RString)
            {
                s = ((RString)o).ToString();
            }
            if (s != null)
            {
                s = s.Trim().Replace("_", "");
                try
                {
                    return(new RFloat(rb, Convert.ToDouble(s)));
                }
                catch
                {
                    throw new eArgError("Invalid valud for Float: \"" + s + "\"");
                }
            }
            return((RFloat)rb.ConvertType(o, typeof(RFloat), "Float", "to_f"));
        }
예제 #3
0
파일: String.cs 프로젝트: retahc/old-code
 public static RString StringToRString(NetRuby ruby, object s)
 {
     return((RString)ruby.ConvertType(s, typeof(RString), "String", "to_str"));
 }