Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your example, it loads from YAML like:</p> <pre><code>{"player"=&gt;{"id"=&gt;1, "label"=&gt;"Player", "badge"=&gt;"NIL"}, "bronze helper"=&gt;{"id"=&gt;2, "label"=&gt;"Bronze Helper", "badge"=&gt;"STF_HELP_BRZ"}, "silver helper"=&gt;{"id"=&gt;3, "label"=&gt;"Silver Helper", "badge"=&gt;"STF_HELP_SLV"}} </code></pre> <p>So all you really seem to need to get rid of is the hash keys. If you only want to keep the values of a hash, you can use the <code>Hash#values</code> method to get (almost) the array you want:</p> <pre><code>pp YAML.load_file("permissionrank.yml").values [{"id"=&gt;1, "label"=&gt;"Player", "badge"=&gt;"NIL"}, {"id"=&gt;2, "label"=&gt;"Bronze Helper", "badge"=&gt;"STF_HELP_BRZ"}, {"id"=&gt;3, "label"=&gt;"Silver Helper", "badge"=&gt;"STF_HELP_SLV"}] </code></pre> <p>The only remaining difference with your example is then that the keys inside those hashes are strings, not symbols. This probably doesn't matter, since Rails is generally really relaxed about that, but just for the sake of example, let's convert those as well. For this you can use the <a href="http://api.rubyonrails.org/classes/Hash.html#method-i-symbolize_keys" rel="nofollow"><code>Hash#symbolize_keys</code></a> method from ActiveSupport.</p> <pre><code>pp YAML.load_file("permissionrank.yml").values.map(&amp;:symbolize_keys) [{id: 1, label: "Player", badge: "NIL"}, {id: 2, label: "Bronze Helper", badge: "STF_HELP_BRZ"}, {id: 3, label: "Silver Helper", badge: "STF_HELP_SLV"}] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload