title: Rails: Assign a constant which can be used in all controllers
body: <p>The class needs to use <code>EWKB</code> in various controller actions, thus defined:</p>
  
  <pre><code>def EWKB
    EWKB = RGeo::WKRep::WKBGenerator.new(:type_format =&gt; :ewkb, :emit_ewkb_srid =&gt; true, :hex_format =&gt; true)
  end
  
  def self.containing_latlon(lat, lon, polygon)
    ewkb = EWKB.generate(FACTORY.point(lon, lat).projection)
    where("ST_Intersects(polygon, ST_GeomFromEWKB(E'\\\\x#{ewkb}'))")
  end
  </code></pre>
  
  <p>The above definition, returns <code>syntax error: dynamic constant assignment</code>.
  In its stead, I defined</p>
  
  <pre><code>def EWKB
    RGeo::WKRep::WKBGenerator.new(:type_format =&gt; :ewkb, :emit_ewkb_srid =&gt; true, :hex_format =&gt; true)
  end
  </code></pre>
  
  <p>and the error disappears.  As the second method needs to invoke it, I am not certain how/if ruby will handle this constructor as</p>
  
  <pre><code>def self.containing_latlon(lat, lon, polygon)
    EWKB = RGeo::WKRep::WKBGenerator.new(:type_format =&gt; :ewkb, :emit_ewkb_srid =&gt; true, :hex_format =&gt; true)
    ewkb = EWKB.generate(FACTORY.point(lon, lat).projection)
    where("ST_Intersects(polygon, ST_GeomFromEWKB(E'\\\\x#{ewkb}'))")
  end
  </code></pre>
  
  <p>leads to the same spot</p>