|
|
|
SearchCategories
Books by the AuthorTwitter AccountOther Ruby Projects |
String Has Other Methods Besides =~ and sub()
Posted over 5 years ago
in Early Steps and Ruby Tutorials.
Ask anyone who knows me and they will tell you I'm a huge fan of regular expressions. I use them all the time and my First, we have:
That snippet is like calling for a military escort (the regular expression engine) to see you safely to the grocery store down the block. That's fun, but probably overkill. In this case, a call to
That may be more like riding you bike to the grocery store, but it gets the job done and is a bit faster to boot. Funny example number two. I've seen this before:
Again, the regular expression engine appreciates the love, but you really just want ==:
Even for some of the fancier stuff, you don't need a full blown regular expression. For example, this:
could be:
You get the idea. I'm not trying to ban regular expressions. Instead, I just think people should remember there are a lot of other methods in String. When you have a few moments, look up these guys in the documentation:
|
|
|
|
you are my programming star.
Your feeds are broken? feedvalidator won't even hit the pageā¦
Feeds should be fixed now. Sorry for the downtime.