Skip to content

Instantly share code, notes, and snippets.

@rentalcustard
Created February 3, 2011 16:13
Show Gist options
  • Save rentalcustard/809694 to your computer and use it in GitHub Desktop.
Save rentalcustard/809694 to your computer and use it in GitHub Desktop.
Genius legacy code
class String
def replace_line_break
return String.new if self.nil?
return_str = String.new
return_str = self.gsub(/[\x0D|\x0A]/,'<br />')
return return_str
end
end
module SalaryFormatting
def self.included(base)
base.module_eval do
extend ClassMethods
end
end
def formatted_salary
salary && self.class.pad_salary(self.salary)
end
module ClassMethods
def pad_salary(salary)
stripped = attr.to_s.gsub(/\D/, "")
( "%8d" % stripped ).gsub(' ', '0')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment