Skip to content

Instantly share code, notes, and snippets.

@luizcarvalho
Created December 1, 2008 23:38
Show Gist options
  • Save luizcarvalho/30904 to your computer and use it in GitHub Desktop.
Save luizcarvalho/30904 to your computer and use it in GitHub Desktop.
def format_number!
if self.instance_of? Cpf
@numero =~ /(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})/
@numero = "#{$1}.#{$2}.#{$3}-#{$4}"
else
@numero =~ /(\d{2})\.?(\d{3})\.?(\d{3})\/?(\d{4})-?(\d{2})/
@numero = "#{$1}.#{$2}.#{$3}/#{$4}-#{$5}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment