Twitter Updates

Tuesday 23 September 2008

Ruby case-insensitive test

Three Ruby methods for case insensitive string matching.
'Ruby' can be replaced by any String or variable of type string

if 'Ruby'.downcase == 'ruby' then
print("'Ruby'.downcase == 'ruby' true \n")
end
if 'Ruby' =~ /^ruby$/i then
print("'Ruby' =~ /^ruby$/i true \n")
end
if 'Ruby'.casecmp('ruby') == 0 then
print("'Ruby'.casecmp('ruby') true \n")
end

No comments: