
class Symbol

  # Easily manipulate undercores on symbols.
  #
  #   :a.pad(2)         #=> :__a__
  #   :__a__.pad(-1)    #=> :_a_
  #
  def pad(i=1)
    return self if i == 0
    s = self.to_s
    if i > 0
      return ( ('_'*i) + self.to_s + ('_'*i) ).to_sym
    else
      i *= -1
      return s[i..-i-1].to_sym if s[0..i-1] == ('_'*i) and s[-i..-1] == ('_'*i)
      return self
    end
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCSymbol < Test::Unit::TestCase

    def test_pad
      assert_equal( :__a__, :a.pad(2) )
      assert_equal( :_a_, :__a__.pad(-1) )
    end

  end

=end
