Skip to content

Commit

Permalink
memoize calculated ip without additional variable
Browse files Browse the repository at this point in the history
There is no need in additional `@calculated_ip` instance variable.
  • Loading branch information
lest committed Nov 1, 2012
1 parent 694334c commit 43aa2d3
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 }x


def initialize(env, middleware) def initialize(env, middleware)
@env = env @env = env
@middleware = middleware @middleware = middleware
@calculated_ip = false @ip = nil
end end


# Determines originating IP address. REMOTE_ADDR is the standard # Determines originating IP address. REMOTE_ADDR is the standard
Expand Down Expand Up @@ -100,9 +100,7 @@ def calculate_ip
end end


def to_s def to_s
return @ip if @calculated_ip @ip ||= calculate_ip
@calculated_ip = true
@ip = calculate_ip
end end


private private
Expand Down

0 comments on commit 43aa2d3

Please sign in to comment.