When you're going through an array or hash (in this case GameObj.npcs array) you refer to each element of the array as something, in this case I chose i, but you can use whatever you want really.
So you tell the script that for this block of code (everything within the {} brackets) that you will be referring to each element of the array as whatever is within the || symbols, in this case i.
Now the script is going through each element of the array and referring to it as i and it's checking to see if i has the same name as what you specified in the first command line variable.
What's being used here is a Regular Expression, or regex for short. You can use an exact match, for example if you watched to match "short sword" exactly you could do i.name == "short sword", so if the weapon name were "broad sword" it wouldn't match because it's not an exact match for "short sword".
A regex lets you match things in a way that isn't an exact match. So you could do a regex for a match of "sword" and it would match both a "short sword" and a "broad sword." To do a regex you do something like
if i.name =~ /sword/
There's a lot more to regexes than this but that's the general gist of it.
You would use two equal signs and quotes if you want an exact match:
if example_variable == "text"
Would mean you're checking if the variable example_variable were an exact match for "text."
A regex would be written as:
if example_variable =~ /text/
Would mean as long as example_variable contained the letters "text" in that exact order anywhere then it would be a match.
So if example_variable were set to "this is a whole lotta text!"
Then using the examples above it would not be an exact match via using == because "this is a whole lotta text!" doesn't match "text" exactly.
However if you were using the regex it would be a match because the word "text" appears somewhere in the variable. You have to be careful with regexes because it might match something you're not even thinking about. For example if you were looking for "text" but the variable had the word "context" in it then it would still match because "text" appears in the word "context."