Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Prevent warning for uninitialized `@cached_options` #129

Closed
wants to merge 1 commit into from

2 participants

@tooky

The current implementation is generating a warning because @cached_options hasn't been initialized when it's first called.

~/.gem/ruby/1.9.3/gems/multi_json-1.7.7/lib/multi_json.rb:10: warning: instance variable @cached_options not initialized

Using the ||= operator prevents this warning, even though it seems like its doing the assignment twice. Not sure if there's a better option?

@tooky tooky Ensure @cached_options is initialized
The current implementation is generating a warning because `@cached_options` hasn't been initialized when it's first called. 

```
~/.gem/ruby/1.9.3/gems/multi_json-1.7.7/lib/multi_json.rb:10: warning: instance variable @cached_options not initialized
```

Using the `||=` operator prevents this warning, even though it seems like its doing the assignment twice. Not sure if there's a better option?
909989c
@coveralls

Coverage Status

Coverage remained the same when pulling 909989c on tooky:patch-1 into 6ad4124 on intridea:master.

@rwz rwz closed this in 20a3760
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 28, 2013
  1. @tooky

    Ensure @cached_options is initialized

    tooky authored
    The current implementation is generating a warning because `@cached_options` hasn't been initialized when it's first called. 
    
    ```
    ~/.gem/ruby/1.9.3/gems/multi_json-1.7.7/lib/multi_json.rb:10: warning: instance variable @cached_options not initialized
    ```
    
    Using the `||=` operator prevents this warning, even though it seems like its doing the assignment twice. Not sure if there's a better option?
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/multi_json.rb
View
2  lib/multi_json.rb
@@ -7,7 +7,7 @@ module MultiJson
class << self
def cached_options
- @cached_options || reset_cached_options!
+ @cached_options ||= reset_cached_options!
end
def reset_cached_options!
Something went wrong with that request. Please try again.