Permalink
Browse files

Merge pull request #8019 from lest/patch-1

memoize calculated ip without additional variable
  • Loading branch information...
spastorino committed Nov 1, 2012
2 parents 694334c + 43aa2d3 commit 2e20a7d9f7555ec50ba6b364ba5a5861c5f9bc95
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 2e20a7d

Please sign in to comment.