Details

Description

The pattern of using more than one argument to determine if an array should be returned is not idiomatic. Consider the case of a multi-get in an application where I have n items to return. If there happens to be only one item it will be treated differently than if there happens to be 2 items.

This forces the application user to wrap all results with a check to see if the result is an array or not in every use of the command

Sergey Avseyev
added a comment - 11/Apr/12 12:55 AM Indeed. What if I leave current get implementation, but now will return Array if the keys passed as Array, even if there was single element there:
get(["foo"]) #=> ["bar"]
get("foo") #=> "bar"
In this case the method behaviour will be consistent. What do you think?

Sergey Avseyev
added a comment - 11/Apr/12 1:40 PM The latter case is working actually
1.9.2p318 (main):011:0> Couchbase.bucket.get("x", "y", :extended => true)
{"x"=>["xval", 0, 12204754167235346432], "y"=>["yval", 0, 15062578311643791360]}
1.9.2p318 (main):012:0> Couchbase.bucket.get(["x", "y"], :extended => true)
{"x"=>["xval", 0, 12204754167235346432], "y"=>["yval", 0, 15062578311643791360]}
In first case I'm returning just array because it has the same order as arguments. So that you can assign them directly to variables:
x, y = Couchbase.bucket.get(["x", "y"])
and you can easily build a Hash from it
keys = ["x", "y"]
vals = Couchbase.bucket.get(keys)
Hash[keys.zip(vals)] #=> {"x"=>"xval", "y"=>"yval"}
The version with such behaviour already published, I can create wrapper which will do it for you, or add new option.