From mboxrd@z Thu Jan 1 00:00:00 1970 From: dato@net.com.org.es (=?utf-8?q?Adeodato=20Sim=C3=B3?=) Date: Thu, 30 Jul 2009 17:57:16 +0200 Subject: [sup-talk] [PATCH] HookContext::method_missing(): allow locals to be nil In-Reply-To: <20090730155656.GA20442@chistera.yi.org> References: <20090730155656.GA20442@chistera.yi.org> Message-ID: With the previous implementation of method_missing() in HookContext, it was not possible to set the value of a local to nil, since that would be assumed to mean "that local does not exist" and super would get called. Now we use has_key? to check whether the local exists or not, and nil will be returned normally from method_missing if that's the value of the @__locals[name]. Signed-off-by: Adeodato Sim? --- lib/sup/hook.rb | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/sup/hook.rb b/lib/sup/hook.rb index 0a0a2f6..8a52a96 100644 --- a/lib/sup/hook.rb +++ b/lib/sup/hook.rb @@ -20,13 +20,15 @@ class HookManager attr_writer :__locals def method_missing m, *a - case @__locals[m] - when Proc - @__locals[m] = @__locals[m].call(*a) # only call the proc once - when nil + if not @__locals.has_key? m super else - @__locals[m] + case @__locals[m] + when Proc + @__locals[m] = @__locals[m].call(*a) # only call the proc once + else + @__locals[m] + end end end -- 1.6.3.3