This:


 def to_words
    string_fragment= []
    num = self

    if num >= 1_000_000
      millions = num/1_000_000
      string_fragment << "%s million" % hundreds_helper(millions)
      num -= millions*1_000_000
    end

    if num >= 1_000
      thousands = num/1_000
      string_fragment << "%s thousand" % hundreds_helper(thousands)
      num -= thousands*1_000
    end

    string_fragment << hundreds_helper(num)
    string_fragment.join(' ')

  end



can be changed to:


 def to_words
    string_fragment= []
    num = self

    if num >= 1_000_000
      millions = num/1_000_000
      string_fragment << "%s million" % hundreds_helper(millions)
      num -= millions*1_000_000
    end

    if num >= 1_000
      thousands = num/1_000
      string_fragment << "%s thousand" % hundreds_helper(thousands)
      num -= thousands*1_000
    end

    if num > 0
      string_fragment << hundreds_helper(num)
    end

    string_fragment.join(' ')

  end

-- 
Posted via http://www.ruby-forum.com/.