From: "Ara.T.Howard" Date: 2004-02-17T00:34:55+09:00 Subject: Re: Hash#values_at On Mon, 16 Feb 2004, Yukihiro Matsumoto wrote: > Date: Mon, 16 Feb 2004 15:33:59 +0900 > From: Yukihiro Matsumoto > Newsgroups: comp.lang.ruby > Subject: Re: Hash#values_at > > Hi, > > In message "Hash#values_at" > on 04/02/16, "Ara.T.Howard" writes: > | > |what is the rational behind this? > | > | ({}.values_at :a).empty? #=> false > | > |i would expect > | > | ({}.values_at :a) #=> nil > | > |or > | > | ({}.values_at :a) #=> [] > | > |but not the actual > | > | ({}.values_at :a) #=> [nil] > | > |there must be some reason for this, but i cannot see why returning an 'array > |full of nothing' is preferable to returning an 'emtpy array'... is there some > |way of thinking about this that will make it seem less suprising? > > def values_at(*args) > args.collect do |i| > self[i] > end > end > > matz. ah. also irb(main):001:0> {:k=>:v}.values_at => [] thanks. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done ===============================================================================