You should probably use standard library for this. It'll make things a little more easy to understand:

```ruby
# script_name => "excite.pig"
File.basename(script_name, ".*")
  => "excite"

# script_name => "excite"
File.basename(script_name, ".*")
  => "excite"

# script_name => "excite.py"
File.basename(script_name, ".*")
  => "excite"
```