`class_eval` -> `define_method`

This provides a call-time speedup and is easier to read.

This PR picks up from the work done in https://github.com/rails/rails/pull/10765. Here's the benchmark I used:
```ruby
require 'benchmark/ips'
require 'minitest'

Benchmark.ips do |x|
  x.config(:time => 5, :warmup => 2)

  x.report('relations_test') do
    begin
      $stdout = File.new('/dev/null', 'w')
      Minitest.run %w(test/cases/relations_test.rb)
    ensure
      $stdout = STDOUT
    end
  end
end
```

And the results:
```
~/Development/rails/activerecord define-method|REBASE-i 1/2 ruby -Itest ar_bench.rb
Calculating -------------------------------------
      relations_test       100 i/100ms
-------------------------------------------------
      relations_test     1109.4 (±14.1%) i/s -       5500 in   5.058918s
~/Development/rails/activerecord define-method|REBASE-i 1/2 git rebase --continue
Stopped at c877a5e6492834f4e4bfafcd6492e0e2c0df3ed5... `class_eval` -> `define_method`
You can amend the commit now, with

	git commit --amend

Once you are satisfied with your changes, run

	git rebase --continue

~/Development/rails/activerecord define-method|REBASE-i 2/2 ruby -Itest ar_bench.rb
Calculating -------------------------------------
      relations_test        95 i/100ms
-------------------------------------------------
      relations_test     1319.2 (±7.0%) i/s -       6650 in   5.066859s
```

Closes #10765