title: define method inside block
body: <p>I'm new to ruby, I'm studying ruby by writing unittest with RSpec, and there is one line of code I can't understand in RSpec when define custom matcher.</p>
  
  <pre><code>RSpec::Matchers.define :be_a_multiple_of do |expected|
    match do |actual|
      do_the_math(actual, expected)
    end
  
    def do_the_math(actual, expected)
      actual % expected == 0
    end
  end
  </code></pre>
  
  <p>as far as I know, ruby is a script language that the compiler read the code sequencly. that is said you must define the method before you use it. but in RSpec, when I define a custom matcher, I could define the helper method after I call it.</p>
  
  <p>I have write the test code to test the fact that it will fail if I call the method before I define it and I also read a little source code from RSpec the define method actually is a wrapper of define_method and pass the delegate as block. but I still can't understand how this code work.</p>
  
  <p>can somebody help me out? just a brief explaination of how this work</p>