Skip to content

Commit

Permalink
Merge pull request #8019 from lest/patch-1
Browse files Browse the repository at this point in the history
memoize calculated ip without additional variable
  • Loading branch information
spastorino committed Nov 1, 2012
2 parents 694334c + 43aa2d3 commit 2e20a7d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions actionpack/lib/action_dispatch/middleware/remote_ip.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2e20a7d

Please sign in to comment.