Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (31 sloc) 1.24 KB
date tags
2017-03-21T11:33:55+09:00
en
programming

zero indent

As I wrote earlier, I don't use a debugger, lately I've started placing the puts, p and pp I use to help me develop at indentation zero, like this:


    def self.get_tzone(o)

p [ :gtz, o ]
      return nil if o == nil
      return local_tzone if o == :local

      return o if o.is_a?(::TZInfo::Timezone)

      if o.is_a?(Numeric)
        i = o.to_i
        sn = i < 0 ? '-' : '+'; i = i.abs
        hr = i / 3600; mn = i % 3600; sc = i % 60
        o = (sc > 0 ? "%s%02d:%02d:%02d" : "%s%02d:%02d") % [ sn, hr, mn, sc ]
      end

      return nil unless o.is_a?(String)

      return ::TZInfo::Timezone.get('Zulu') if o == 'Z'

      z = (@custom_tz_cache ||= {})[o]
      return z if z

      z = (::TZInfo::Timezone.get(o) rescue nil)
      return z if z

      z = get_offset_tzone(o)
      return z if z

      nil
    end

The code that is here for debugging immediately stands out. I can easily locate it with the /^p regular expression as well.

Example taken out of et-orbi.