Fake Rails environment

For testing some bits inside of ActiveRecord proper.

<span style="color:#9966CC; font-weight:bold;">module</span> Rails
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">env</span>
    o = <span style="color:#9966CC; font-weight:bold;">Class</span>.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#9966CC; font-weight:bold;">def</span> production?
        <span style="color:#0000FF; font-weight:bold;">true</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    o.<span style="color:#9900CC;">new</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>

Evil and fun. Uses `Class.new`, my favorite Ruby method.

Muahahaha.

This entry was posted in Code, Curated and tagged , . Bookmark the permalink.

2 Responses to Fake Rails environment

  1. Eric Hodel says:

    But you can do it without the Class.new:

    o = Object.new
    def o.production?() true end
     o

  2. Adam Keys says:

    Well done. But, I say, what’s the fun in that? ;)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Comments will be sent to the moderation queue.