<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users1228</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/1228" rel="self"/>
  <title>sebastian.deutsch.myopenid.com</title>
  <updated>Tue Sep 08 16:14:23 -0700 2009</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code1027</id>
    <published>2009-09-08T16:14:23-07:00</published>
    <updated>2009-09-09T17:54:42-07:00</updated>
    <title>[Ruby] Call a function to each member</title>
    <content type="html">&lt;p&gt;Is there a shorter version, or do I always have to code the block syntax? Something like @documents.collect_call(:to_hash)? Btw. It's Rails so maybe there might be something in ActiveSupport.&lt;/p&gt;

&lt;pre&gt;@public_documents = @documents.map { |document| document.to_hash }
&lt;/pre&gt;</content>
    <author>
      <name>sebastian.deutsch.myopenid.com</name>
      <email>sebastian.deutsch@9elements.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1027-call-a-function-to-each-member" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code931</id>
    <published>2009-06-24T15:38:44-07:00</published>
    <updated>2009-07-05T18:56:04-07:00</updated>
    <title>[Ruby] Named Scopes in Relations</title>
    <content type="html">&lt;p&gt;I have two models: Teams and Statements. A statement belongs to a team. When I try to apply a scope to the relation - I can do this with anonymous scopes. Is there a possibility to define a named scope for a relation? When I define it in my Statement Model, it will say method_is missing. Any hints?
&lt;/p&gt;

&lt;pre&gt;@team.statements.scoped({ 
               :select =&amp;gt; &amp;quot;statements.*, users.first_name&amp;quot;,
               :joins =&amp;gt; &amp;quot;INNER JOIN users ON users.id = statements.user_id&amp;quot;,
               :order =&amp;gt; 'RAND()',
               :limit =&amp;gt; '100'}).to_json&lt;/pre&gt;</content>
    <author>
      <name>sebastian.deutsch.myopenid.com</name>
      <email>sebastian.deutsch@9elements.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/931-named-scopes-in-relations" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code908</id>
    <published>2009-06-10T18:01:09-07:00</published>
    <updated>2009-06-22T19:01:16-07:00</updated>
    <title>[Ruby] Decoding a json object while converting keys to symbols</title>
    <content type="html">&lt;p&gt;I'm decoding a json object. The first line would be sufficient - but then I can only access the items with item[&amp;quot;foo&amp;quot;]. I appreciate item[:foo]. Is there a more elegant way to do that?&lt;/p&gt;

&lt;pre&gt;def schema
  raw_schema_json = ActiveSupport::JSON.decode(self.schema_json)
  schema = []
  raw_schema_json.each do |raw_item|
    item = {}
    raw_item.each do |key, value|
      item[key.to_sym] = value
    end
    schema.push(item)
  end
  schema
end&lt;/pre&gt;</content>
    <author>
      <name>sebastian.deutsch.myopenid.com</name>
      <email>sebastian.deutsch@9elements.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/908-decoding-a-json-object-while-converting-keys-to-symbols" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code722</id>
    <published>2009-01-27T17:19:16-08:00</published>
    <updated>2010-10-08T10:18:21-07:00</updated>
    <title>[JavaScript] Get the id of a &lt;select&gt; with jQuery</title>
    <content type="html">&lt;p&gt;I get a change event within the select and now I need the id of the corresponding &amp;lt;select&amp;gt;. I was successfull with filter.get(0).id, but I believe there is a more jQuery way to do this.&lt;/p&gt;

&lt;pre&gt;$('.answer_filter').change(function() {
  var filter = jQuery(this);
  var select = jQuery('#' + filter.get(0).id); // @TODO find a more appropriate solution
  ...
});&lt;/pre&gt;</content>
    <author>
      <name>sebastian.deutsch.myopenid.com</name>
      <email>sebastian.deutsch@9elements.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/722-get-the-id-of-a-select-with-jquery" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code674</id>
    <published>2008-12-18T12:39:32-08:00</published>
    <updated>2008-12-23T06:59:31-08:00</updated>
    <title>[Ruby] Ugly RegEx Accessor</title>
    <content type="html">&lt;p&gt;I try to extract an id from a string. The string will look like &amp;quot;category-1337&amp;quot; and I want my result to be 1337. Surely I could use string slicing but I sometimes I need more power.&lt;/p&gt;

&lt;pre&gt;category_id = category_name.scan(/category-(\d+)/)[0][0]&lt;/pre&gt;</content>
    <author>
      <name>sebastian.deutsch.myopenid.com</name>
      <email>sebastian.deutsch@9elements.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/674-ugly-regex-accessor" rel="alternate"/>
  </entry>
</feed>

