Skip to content

Instantly share code, notes, and snippets.

@benshimmin
Created March 11, 2012 12:23
Show Gist options
  • Save benshimmin/2016246 to your computer and use it in GitHub Desktop.
Save benshimmin/2016246 to your computer and use it in GitHub Desktop.
Nice pattern for utility classes in CoffeeScript
Utils =
Math :
class MathUtils
@clamp : (num, min, max) ->
return min if num < min
return max if num > max
num
String :
class StringUtils
@trimLeft : (str) ->
str.replace /^\s+/, ""
@trimRight : (str) ->
str.replace /\s+$/, ""
(exports ? @).Utils = Utils
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment