Skip to content

Instantly share code, notes, and snippets.

@joshnesbitt
Created February 15, 2010 12:28
Show Gist options
  • Select an option

  • Save joshnesbitt/304609 to your computer and use it in GitHub Desktop.

Select an option

Save joshnesbitt/304609 to your computer and use it in GitHub Desktop.
module PercentagePatch
module InstanceMethods
def as_percentage_of(total)
return 0 if total == 0
self.to_f / total * 100
end
end
end
Integer.instance_eval do
include PercentagePatch::InstanceMethods
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment