title: Override Kernel Method in Ruby
body: <p>I'm working through a programming exercise where I have to override the <code>rand</code> kernel method in Ruby. </p>
  
  <p>I've tried</p>
  
  <pre><code>module Kernel
    def rand(max=0)
      return 0
    end
  end
  </code></pre>
  
  <p>And I've tried</p>
  
  <pre><code>class Random
    def rand(max=0)
     return 0
    end
  end 
  </code></pre>
  
  <p>neither seem to work. How should I go about doing this?</p>
  
  <p>Edit: </p>
  
  <p>I realized the bug. I should have written</p>
  
  <pre><code>module Kernel
    def self.rand(max=0)
      0
    end
  end
  </code></pre>
  
  <p>I was not calling just plain rand() but Kernel::rand() and it seems that calling it that way requires to override with <code>self</code> in front.  Can anyone explain why that is? Thanks</p>