Beispiel #1
0
        public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
        {
            string fname;
            foreach_arg arg = new foreach_arg();

            if (Class.rb_scan_args(caller, args.ToRubyArray(), 1, 1, false) == 2)
                arg.sep = String.StringValue(args[1], caller);
            fname = String.StringValue(args[0], caller);

            if (args.Length == 1)
            {
                arg.sep = String.StringValue(IO.rb_default_rs.value, caller);
            }
            
            arg.io = IO.rb_io_open(fname, "r", caller);
            if (arg.io == null)
                return null;

            object result = null;
            try
            {
                result = io_s_foreach(caller, args.block, arg);
            }
            finally
            {
                IO.rb_io_close(arg.io);
            }

            return result;
        }
Beispiel #2
0
        private static object io_s_foreach(Frame caller, Proc block, foreach_arg arg)
        {
            String str;

            while ((str = IO.rb_io_getline(arg.sep, arg.io, caller)) != null)
            {
                Proc.rb_yield(block, caller, str);
            }

            return null;
        }