diff options
author | Sergey Nartimov <just.lest@gmail.com> | 2012-10-24 14:32:32 +0300 |
---|---|---|
committer | Sergey Nartimov <just.lest@gmail.com> | 2012-11-01 22:29:21 +0300 |
commit | 43aa2d308c27f387f2ea3051170769bb60b99015 (patch) | |
tree | b53e92bab09cdb6eade08882ce5bf4e4a730f071 /actionpack/lib/action_dispatch | |
parent | 694334c37a95e85e686b121ce5cb2ccb4114e6b5 (diff) | |
download | rails-43aa2d308c27f387f2ea3051170769bb60b99015.tar.gz rails-43aa2d308c27f387f2ea3051170769bb60b99015.tar.bz2 rails-43aa2d308c27f387f2ea3051170769bb60b99015.zip |
memoize calculated ip without additional variable
There is no need in additional `@calculated_ip` instance variable.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/remote_ip.rb | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/remote_ip.rb b/actionpack/lib/action_dispatch/middleware/remote_ip.rb index ec15a2a715..5abf8f2802 100644 --- a/actionpack/lib/action_dispatch/middleware/remote_ip.rb +++ b/actionpack/lib/action_dispatch/middleware/remote_ip.rb @@ -63,9 +63,9 @@ module ActionDispatch }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 @@ module ActionDispatch end def to_s - return @ip if @calculated_ip - @calculated_ip = true - @ip = calculate_ip + @ip ||= calculate_ip end private |