From: Tilman Sauerbeck Date: Wed, 21 Sep 2005 15:56:55 +0000 (+0000) Subject: Added Description#inherit. X-Git-Tag: redact-0.1.5~4 X-Git-Url: http://git.code-monkey.de/?p=redact.git;a=commitdiff_plain;h=237a825fb05bc8d9128c8711aa46e112a5b91c62 Added Description#inherit. --- diff --git a/ChangeLog b/ChangeLog index 0d8db55..d443d03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,10 @@ -- -$Id: ChangeLog 69 2005-09-19 20:17:07Z tilman $ +$Id: ChangeLog 70 2005-09-21 15:56:55Z tilman $ ++ +2005-09-21 Tilman Sauerbeck (tilman at code-monkey de) + * lib/redact/part.rb: Added Description#inherit + 2005-09-19 Tilman Sauerbeck (tilman at code-monkey de) * lib/redact/part.rb: Fixed ImageDescription#set_border, which used the "right" argument for the "left" border diff --git a/lib/redact/part.rb b/lib/redact/part.rb index 692a487..3446de2 100644 --- a/lib/redact/part.rb +++ b/lib/redact/part.rb @@ -1,5 +1,5 @@ #-- -# $Id: part.rb 69 2005-09-19 20:17:07Z tilman $ +# $Id: part.rb 70 2005-09-21 15:56:55Z tilman $ # # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) # @@ -245,6 +245,20 @@ module Redact @color_class = "" end + def inherit(other) + unless other.is_a?(Description) + raise(ArgumentError, "Cannot inherit from description") + end + + prot = ["@name", "@value"] + + (instance_variables - prot).each do |v| + n = other.instance_variable_get(v.intern) + n = n.dup rescue n + instance_variable_set(v.intern, n) + end + end + def visible=(v) @visible = (v == true) end