When RSpec::Matcher.define is called, it is passed the name of a matcher ( which in this case is be_a_multiple_of ) and a block

The argument passed to that block is the expected value. This is the value passed as the matcher argument when running a spec, which would be 3 in this case be_a_multiple_of(3)

match do |actual|

Inisde that block, the match method is called which is also passed a block. That block takes one argument, actual, which is the value passed to expect when the matcher is invoked. In this case that would be 9, expect(9).to be_multipe_of(3)

The block just does some calculation using actual and expected to return true or false.

How does actual refer to 9?

RSpec.describe 9 do

In this case the value 9 is exposed as the subject for the example group because it is passed as the argument to the outermost example group as stated here In other words it's the same as writing subject { 9 }

If you check the RSpec docis_expected is basically the same as writing expect(subject).

{ is_expected.to be_a_multiple_of(3) }

is the same as

{ expect(subject).to be_a_multiple_of(3) }

And as stated earlier the object passed to expect method is what is used as the actual argument for the block passed to the match method. That's how actual refers to 9