Permalink
Browse files

add String#starts_with?:

  • Loading branch information...
1 parent bec9b93 commit 27ce7ef53d3268c8283e9f2b80841614c26a7204 @bakkdoor committed Dec 6, 2012
Showing with 14 additions and 0 deletions.
  1. +4 −0 lib/string.fy
  2. +10 −0 tests/string.fy
View
@@ -281,4 +281,8 @@ class String {
{ return false } if: blank?
lowercase == self
}
+
+ def starts_with?: string {
+ from: 0 to: (string size - 1) == string
+ }
}
View
@@ -264,4 +264,14 @@ FancySpec describe: String with: {
"A" lowercase? is: false
"abc" lowercase? is: true
}
+
+ it: "returns true if its begins with another string" with: 'starts_with?: when: {
+ "" starts_with?: "" . is: true
+ "foo" starts_with?: "f" . is: true
+ "foo" starts_with?: "fo" . is: true
+ "foo" starts_with?: "foo" . is: true
+ "foo" starts_with?: "fooo" . is: false
+ "foo" starts_with?: "oo" . is: false
+ "foo" starts_with?: "" . is: false
+ }
}

0 comments on commit 27ce7ef

Please sign in to comment.