Skip to content

Instantly share code, notes, and snippets.

@xxx
Created August 7, 2010 01:55
Show Gist options
  • Save xxx/512325 to your computer and use it in GitHub Desktop.
Save xxx/512325 to your computer and use it in GitHub Desktop.
class String
define_method :starts_with? do |other|
head = self[0, other.length]
head == other
end unless defined?(:starts_with?)
define_method :ends_with? do |other|
tail = self[-1 * other.length, other.length]
tail == other
end unless defined?(:ends_with?)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment