For instance, is the string "Hello, world"
uppercase? Or is it lowercase? Is it sentence-case? Titlecase? So your methods, simple as they are, are perhaps too simple to make sense when applied outside the (narrow) usage you've tailored them for. As such, they probably shouldn't be global String
methods. Certainly, you don't need to extend a core class like String
just for such a simple ==
comparison, it's a bit much to extend a core class like string.
Also, Ruby convention is to skip thenot use an is_
prefix on interrogatory methods like those. The nil?
method, for instance, isn't called is_nil?
. Same for one?
, any?
, empty?
, include?
and so on.
- There's a
String#chars
method, which'll give you an array of chars - no need for split - Instead of zipping, use a loop and use an index - characters in a string can be accessed just like elements in an array.
- And if you're going to loop, no need to loop further than the shortest of the two strings. Or, if you zip the arrays like you do right now, make sure you
break
the loop when one string or the other "runs out" - You only need to check for uppercase. Everything else gets downcased by default. A character can only be upper or lowercase, so if it's not uppercase, you already know that it's lowercase; no need for extra
if
s (seebut see the update below)