From: Intransition Date: 2012-01-16T09:30:47+09:00 Subject: The Better Code ------=_Part_1587_19647082.1326673842786 Content-Type: multipart/alternative; boundary="----=_Part_1588_32901699.1326673842786" ------=_Part_1588_32901699.1326673842786 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Which would you judge to be the better code? The concise: def self.assert(*a, &b) o = Hash === a.last ? a.pop : {} t = o[:backtrace] || caller m = o[:message] e = new(m, *a, &b) e.set_backtrace(t) e.assert end Or the more explicit: def self.assert(*arguments, &block) options = (Hash === arguments.last ? arguments.pop : {}) backtrace = options[:backtrace] || caller message = options[:message] assay = new(message, *arguments, &block) assay.set_backtrace(backtrace) assay.assert end Which and why? ------=_Part_1588_32901699.1326673842786 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Which would you judge to be the better code?

The concise:

    def self.assert(*a, &b)
      o = Hash === a.last ? a.pop : {}

      t = o[:backtrace] || caller
      m = o[:message]

      e = new(m, *a, &b)
      e.set_backtrace(t)
      e.assert
    end

Or the more explicit:

    def self.assert(*arguments, &block)
      options = (Hash === arguments.last ? arguments.pop : {})

      backtrace = options[:backtrace] || caller
      message   = options[:message]

      assay = new(message, *arguments, &block)
      assay.set_backtrace(backtrace)
      assay.assert
    end

Which and wh y?
------=_Part_1588_32901699.1326673842786-- ------=_Part_1587_19647082.1326673842786--