Skip to content

Instantly share code, notes, and snippets.

@mycargus
Created January 12, 2016 18:13
Show Gist options
  • Select an option

  • Save mycargus/046cba8a0b78446cbd83 to your computer and use it in GitHub Desktop.

Select an option

Save mycargus/046cba8a0b78446cbd83 to your computer and use it in GitHub Desktop.
class String
def trim sep=/\s/
sep_source = sep.is_a?(Regexp) ? sep.source : Regexp.escape(sep)
pattern = Regexp.new("\\A(#{sep_source})*(.*?)(#{sep_source})*\\z")
self[pattern, 2]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment