Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class String
- def starts_with?(str)
- return false if self.length < str.length
- return true if self[0, str.length] == str
- return false
- end
- def ends_with?(str)
- return self.reverse.starts_with?(str.reverse)
- end
- end
- Example:
- "hello".starts_with?("hell") # => Returns true
- "hello world!".ends_with?("world") # => Returns false (because it has an exclamation point, for which I'm not checking)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement