From: ahoward Date: 2003-06-18T03:06:24+09:00 Subject: Re: [RCR] Array#push(empty array expanded) => no exception On Tue, 17 Jun 2003, Simon Strandgaard wrote: > This strange behavier really surprised me.. > > irb(main):006:0> [].push(*[]) > ArgumentError: wrong number arguments (at least 1) > from (irb):6:in `push' > from (irb):6 > > > Why is it illigal to concatenate an empty set ? > I expected Rubys Array class to work just like a normal set. > This seems *VERY* non-intuitive to me (POLS). > > Array#unshift doesn't like zero arguments neither. > > > An ugly hack to avoid it could be: > @data.unshift(*objs) unless objs.empty? > > > > Can it be made legal to push/unshift with zero arguments ? and what would it do? create a stack frame, and then return? to call a function which does nothing is much more an expense than simply doing [].push *[] unless [].empty? [].unshift *[] unless [].empty? or even [].push *[] rescue nil [].unshift *[] rescue nil i think under normal conditions people would consider it an error to call a method which becomes a no-op, without so much as a warning, when called with no arguments. *that* would violate my POLS. my 2 cents. -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ara.t.howard@noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 | ~ > ruby -e 'p(%.\x2d\x29..intern)' ====================================