Shopify/wolverine — pull request #6 by bitterb (2013-03-31 11:46:08+00:00)
Title: Cache methods on Wolverine

This pull request adds a method cache mechanism as suggested in TODO. I would appreciate it if you could kindly review and give any comments.

Currently, the code below always calls Wolverine.method_missing because it does not cache `mexists` as a method.

```ruby
redis = Redis.new
redis.set(:foo, :foo)
Wolverine.config.redis = redis
Wolverine.config.script_path = Pathname.new(File.join(here, 'examples'))
p Wolverine.methods.include?(:mexists) # => false
p Wolverine.mexists([:foo, :bar, :baz]) # => [1, 0, 0]
p Wolverine.methods.include?(:mexists) # => false
```

After applying this patch, the same code caches `mexists` as a class method.

```ruby
redis = Redis.new
redis.set(:foo, :foo)
Wolverine.config.redis = redis
Wolverine.config.script_path = Pathname.new(File.join(here, 'examples'))
p Wolverine.methods.include?(:mexists) # => false
p Wolverine.mexists([:foo, :bar, :baz]) # => [1, 0, 0]
p Wolverine.methods.include?(:mexists) # => true
```

And Wolverine.reset! clears cached methods.
```ruby
Wolverine.methods.include?(:mexists) # => true
Wolverine.reset!
Wolverine.methods.include?(:mexists) # => false
```

The method cache works in case that Wolverine objects are instantiated.