repo.or.cz
/
ruby.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git]
/
sample
/
delegate.rb
blob
dc7ea2a0af3145f3f1df67e15939b88a7ba64bdf
1
require 'delegate'
2
3
class ExtArray < DelegateClass(Array)
4
def initialize()
5
super([])
6
end
7
end
8
9
ary = ExtArray.new
10
p ary.class
11
ary.push 25
12
p ary
13
ary.push 42
14
ary.each {|x| p x}
15
16
foo = Object.new
17
def foo.test
18
25
19
end
20
def foo.iter
21
yield self
22
end
23
def foo.error
24
raise 'this is OK'
25
end
26
foo2 = SimpleDelegator.new(foo)
27
p foo2
28
foo2.instance_eval{print "foo\n"}
29
p foo.test == foo2.test # => true
30
p foo2.iter{[55,true]} # => true
31
foo2.error # raise error!