Permalink
Browse files

memoize calculated ip without additional variable

There is no need in additional `@calculated_ip` instance variable.
  • Loading branch information...
1 parent 694334c commit 43aa2d308c27f387f2ea3051170769bb60b99015 @lest lest committed Oct 24, 2012
Showing with 4 additions and 6 deletions.
  1. +4 −6 actionpack/lib/action_dispatch/middleware/remote_ip.rb
@@ -63,9 +63,9 @@ class GetIp
}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 @@ def calculate_ip
end
def to_s
- return @ip if @calculated_ip
- @calculated_ip = true
- @ip = calculate_ip
+ @ip ||= calculate_ip
end
private

0 comments on commit 43aa2d3

Please sign in to comment.