Feature Requests: Browse | Submit New | Admin

[#16155] memcache-client initializer update

Date:
2007-12-07 11:20
Priority:
3
Submitted By:
Tron Fu (tron)
Assigned To:
Mike Perham (mperham)
Category:
memcache-client
State:
Open
Summary:
memcache-client initializer update

Detailed description
Can you replace the line

raise ArgumentError, "wrong number of arguments (#{args.length} for 2)"

with

opts = args.pop if args.last.is_a?( Hash )
servers = args

in the case else portion of the initialize function so that memcache-client will support MemCache.new(*addresses) parameter
notations as Ruby-memcache?

Thanks,
Tron

Original code listed below:

def initialize(*args)
    servers = []
    opts = {}

    case args.length
    when 0 then # NOP
    when 1 then
      arg = args.shift
      case arg
      when Hash   then opts = arg
      when Array  then servers = arg
      when String then servers = [arg]
      else raise ArgumentError, 'first argument must be Array, Hash or String'
      end
    when 2 then
      servers, opts = args
    else
      raise ArgumentError, "wrong number of arguments (#{args.length} for 2)"
    end

    opts = DEFAULT_OPTIONS.merge opts
    @namespace   = opts[:namespace]
    @readonly    = opts[:readonly]
    @multithread = opts[:multithread]
    @mutex       = Mutex.new if @multithread
    @buckets     = []
    self.servers = servers
  end

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
assigned_todrbrain2009-03-31 00:05zenspider