summaryrefslogtreecommitdiff
path: root/lib/delegate.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/delegate.rb')
-rw-r--r--lib/delegate.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/delegate.rb b/lib/delegate.rb
index cb3c730..571bf87 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -7,16 +7,16 @@
#
# Usage:
# foo = Object.new
-# foo = SimpleDelegater.new(foo)
+# foo = SimpleDelegator.new(foo)
# foo.type # => Object
-class Delegater
+class Delegator
def initialize(obj)
preserved = ["id", "equal?", "__getobj__"]
for t in self.type.ancestors
preserved |= t.instance_methods
- break if t == Delegater
+ break if t == Delegator
end
for method in obj.methods
next if preserved.include? method
@@ -30,7 +30,7 @@ class Delegater
end
-class SimpleDelegater<Delegater
+class SimpleDelegator<Delegator
def initialize(obj)
super
@@ -45,3 +45,13 @@ class SimpleDelegater<Delegater
@obj = obj
end
end
+
+# backword compatibility ^_^;;;
+Delegater = Delegator
+SimpleDelegater = SimpleDelegator
+
+if __FILE__ == $0
+ foo = Object.new
+ foo = SimpleDelegator.new(foo)
+ p foo.type # => Object
+end