Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore uppercase using start_with?

Tags:

string

ruby

Is there a better way to ignore uppercase than this?

"Hello".start_with?("hell","Hell") #=> true

I want to check if a string element in an array starts with another string ignoring uppercase, like LIKE % in MySQL.

like image 520
user1364684 Avatar asked Jan 12 '23 13:01

user1364684


1 Answers

I would do something like this:

'Hello'.upcase.start_with?('HELL')

Another approach to the same problem. That's equivalent to do something like UPPER(column) like 'SOMETHING%' in SQL.

like image 169
MurifoX Avatar answered Jan 22 '23 22:01

MurifoX