```ruby
next if if r.to_i(16) != rid
```

would allow you to easily reduce the code complexity of this block of code, which would improve code readability