Develop and Download Open Source Software

Browse CVS Repository

Contents of /netruby/netruby/Enum.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Mon Apr 8 13:27:17 2002 UTC (22 years ago) by arton
Branch: MAIN, vendor
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
initial version 0.8

1 /*
2 Copyright(C) 2001-2002 arton
3
4 Permission is granted for use, copying, modification, distribution,
5 and distribution of modified versions of this work as long as the
6 above copyright notice is included.
7 */
8
9 using System;
10 using System.Text;
11 using System.Globalization;
12 using System.Collections;
13 using System.Reflection;
14 using System.Security;
15
16 namespace arton.NETRuby
17 {
18 public class REnumerable : RModule
19 {
20 private REnumerable(NetRuby rb) :
21 base(rb, "Enumerable")
22 {
23 }
24 internal static object Each(RBasic r)
25 {
26 return r.ruby.Funcall(r, "each");
27 }
28 private static object collect_i(object it, object data, object self)
29 {
30 RArray a = (RArray)data;
31 a.Add(a.ruby.Yield(it));
32 return null;
33 }
34 private static object find_all_i(object it, object data, object self)
35 {
36 RArray a = (RArray)data;
37 object o = a.ruby.Yield(it);
38 if (RTest(o))
39 {
40 a.Add(o);
41 }
42 return null;
43 }
44 private static object enum_all(object it, object data, object self)
45 {
46 ((RArray)data).Add(it);
47 return null;
48 }
49 private static object find_all(RBasic r, params object[] args)
50 {
51 NetRuby ruby = r.ruby;
52 RArray ary = new RArray(ruby, true);
53 ruby.Iterate(new NetRuby.IterationProc(Each), r,
54 new NetRuby.BlockProc(find_all_i), ary);
55 return ary;
56 }
57 private static object collect(RBasic r, params object[] args)
58 {
59 NetRuby ruby = r.ruby;
60 RArray ary = new RArray(ruby, true);
61 ruby.Iterate(new NetRuby.IterationProc(Each), r,
62 (ruby.IsBlockGiven) ? new NetRuby.BlockProc(collect_i) :
63 new NetRuby.BlockProc(enum_all), ary);
64 return ary;
65 }
66
67 internal static void Init(NetRuby rb)
68 {
69 REnumerable en = new REnumerable(rb);
70 rb.mEnumerable = en;
71
72 en.DefineMethod("find_all", new RMethod(find_all), 0);
73 en.DefineMethod("select", new RMethod(find_all), 0);
74
75 en.DefineMethod("collect", new RMethod(collect), 0);
76 en.DefineMethod("map", new RMethod(collect), 0);
77 }
78 }
79 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26