Just a note:

```ruby
ip.split(".").first
```

could be written more effective as
```ruby
ip[0..ip.index(".") - 1]
```

This avoids creating a list with items which you do not need at all.

On the other hand it might be less readable and IP address is a short string so the overhead is small.
And this is also consistent with other cases, so it's up to you...