开发者

NoMethodError using Memcached Sinatra-style

开发者 https://www.devze.com 2023-01-02 07:38 出处:网络
I\'ve just installed Memcached on my Mac and updated my Sinatra app configu开发者_JAVA百科ration as described in Heroku\'s documentation, but I\'m getting a NoMethodError when trying to use the hash-b

I've just installed Memcached on my Mac and updated my Sinatra app configu开发者_JAVA百科ration as described in Heroku's documentation, but I'm getting a NoMethodError when trying to use the hash-based syntax they specify:

>> CACHE['color'] = 'blue'
>> CACHE['color']

Using explicit get and set methods as below seems to work fine.

>> CACHE.set('color', 'blue')
>> CACHE.get('color')

If necessary I can use the latter syntax, but the former seems more elegant. I haven't tested this on Heroku's environment since I'd like whatever implementation I use to work on my local environment as well. Thanks!


You could do this:

class << CACHE
  alias [] get
  alias []= set
end
0

精彩评论

暂无评论...
验证码 换一张
取 消