public
Description: A chess hax in ruby
Clone URL: git://github.com/scrooloose/chesticles.git
added Object#delegate
marty (author)
Thu Feb 28 23:50:56 -0800 2008
commit  bd2e9da3d9ef5d31de7a3d36e49156e50857f242
tree    c3994f242af083c0efce8ea6de25f527c35632c7
parent  a35d2205d42f3247eeb1e3561465fd77dd771033
...
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
0
@@ -34,3 +34,18 @@ class Numeric
0
     self % 2 == 1
0
   end
0
 end
0
+
0
+class Object
0
+ def delegate(*methods)
0
+ options = methods.pop
0
+ if options.is_a?(Hash) && options[:to].nil?
0
+ raise(ArgumentError, "Must specify a target for the delegation with :to, eg delegate(:foo, :to => :bar)")
0
+ end
0
+
0
+ methods.each do |method|
0
+ define_method(method) do
0
+ send(options[:to]).send(method)
0
+ end
0
+ end
0
+ end
0
+end

Comments

    No one has commented yet.