Re: [SPOILER] Ruby RPNCalc (Solution to Quiz #25)
Mike Stok <[email protected]> Sat, 2 Oct 2004 01:05:23 -0400 (EDT)
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
On Fri, 1 Oct 2004, Mike Stok wrote:
> def do(*ops)
> ops.each do |op|
> # Checks for the operation in @@procs, if operation not found there
> # then see if we have a do_<operation> we can use before failing
>
> if p = @@procs[op]
> n_args = p.arity
> raise RuntimeError, "stack empty" if @stack.size < n_args
> args = @stack.shift(n_args)
> @stack.unshift(*p[*args])
> else
> self.send("do_#{op}") rescue raise RuntimeError, "bad command"
> end
> end
> end
Hmmm, args = @stack.shift(n_args) worked for the 2004-09-17 snapsoot, but
args = @stack.slice!(0, n_args)
seems more likely to succeed!
Sorry,
Mike
--
[email protected] | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
| Fingerprint 0570 71CD 6790 7C28 3D60
| 75D2 9EC4 C1C0 0599 13DA