Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #8019 from lest/patch-1

memoize calculated ip without additional variable
  • Loading branch information...
commit 2e20a7d9f7555ec50ba6b364ba5a5861c5f9bc95 2 parents 694334c + 43aa2d3
@spastorino spastorino authored
Showing with 4 additions and 6 deletions.
  1. +4 −6 actionpack/lib/action_dispatch/middleware/remote_ip.rb
View
10 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
Please sign in to comment.
Something went wrong with that request. Please try again.