title: Mimic another Ruby class so the object passes the === type check
body: <p>I want to create an object that acts as a specific class, such as Fixnum, but isn't an instance of that class nor its subclasses.</p>
  
  <p>There are various use-cases for this. In the Fixnum case, I want to define a more specific integer type that is essentially a Fixnum but implements some extra logic, too. I can't subclass Fixnum itself because immediate types such as Fixnum and Symbol can't be subclassed.</p>
  
  <p>Another use-case is mocking in automated tests: sometimes you want to create an object that acts like a certain class (usually a model instance) but is for technical reasons not an instance of that exact class.</p>
  
  <p>Here's how to create a specific integer type that delegates all methods to an internally stored fixnum:</p>
  
  <pre><code>require 'delegate'
  require 'forwardable'
  
  # integer representing a page number
  class PageNumber &lt; DelegateClass(Integer)
    extend Forwardable
  
    def initialize(value, name)
      @name = name
      super(value)
    end
  
    def inspect
      "#{@name} #{to_i}"
    end
  
    alias_method :to_i, :__getobj__
    def_delegators :to_i, :instance_of?, :kind_of?, :is_a?
  end
  </code></pre>
  
  <p>This object can pass <code>is_a?</code> and similar checks:</p>
  
  <pre><code>page = PageNumber.new(1, "page")
  page.is_a? Fixnum  #=&gt; true
  </code></pre>
  
  <p>But nothing I do can make it pass the <a href="http://ruby-doc.org/core-1.8.7/classes/Module.html#M000203" rel="noreferrer"><code>Module#===</code></a> type check:</p>
  
  <pre><code># my problem:
  Fixnum === page    #=&gt; false
  </code></pre>
  
  <p>The fact that my object fails this check is very unfortunate, since the <code>===</code> method is used internally in <code>case</code> statements:</p>
  
  <pre><code>case page
  when Fixnum
    # it will never get here
  when String
    # ...
  else
    # ...
  end
  </code></pre>
  
  <p>My question is how can I create a mock type that passes the <code>===</code> check <em>without</em> augmenting the <code>===</code> methods on built-in classes?</p>