From 43aa2d308c27f387f2ea3051170769bb60b99015 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Wed, 24 Oct 2012 14:32:32 +0300 Subject: memoize calculated ip without additional variable There is no need in additional `@calculated_ip` instance variable. --- actionpack/lib/action_dispatch/middleware/remote_ip.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/middleware/remote_ip.rb b/actionpack/lib/action_dispatch/middleware/remote_ip.rb index ec15a2a715..5abf8f2802 100644 --- a/actionpack/lib/action_dispatch/middleware/remote_ip.rb +++ b/actionpack/lib/action_dispatch/middleware/remote_ip.rb @@ -63,9 +63,9 @@ module ActionDispatch }x def initialize(env, middleware) - @env = env - @middleware = middleware - @calculated_ip = false + @env = env + @middleware = middleware + @ip = nil end # Determines originating IP address. REMOTE_ADDR is the standard @@ -100,9 +100,7 @@ module ActionDispatch end def to_s - return @ip if @calculated_ip - @calculated_ip = true - @ip = calculate_ip + @ip ||= calculate_ip end private -- cgit v1.2.3