Note that there are some explanatory texts on larger screens.

plurals
  1. PORails hash iteration vs Ruby?
    primarykey
    data
    text
    <p>I've been having some weird behavior. It's one of those issues that you look at and feel it shouldn't even be an issue!</p> <p>Here is the skinny.</p> <pre><code>class Partner &lt; ActiveRecord::Base STATUS = { pending: 0, # 0 account has a pending billing request (but is not yet open) active: 1, # 1 account has an active base subscription suspended: 2, # 2 account has been suspended (e.g. after a base subscription decline) expired: 3, # 3 base subscription has expired incomplete: 4, # 4 partner application process incomplete closed: 5, # 5 account has been permanently closed cancelled: 6 # 6 account has been cancelled by user (but is still unexpired) } after_initialize :setup_status_enums def setup_status_enums puts STATUS.inspect STATUS.each do |key, val| puts "Doing enum #{key}" define_method "#{key.to_s}?" do send("status") == key end define_method "#{key.to_s}!" do send("status=", val) end end end end {:pending=&gt;0, :active=&gt;1, :suspended=&gt;2, :expired=&gt;3, :incomplete=&gt;4, :closed=&gt;5, :cancelled=&gt;6} Doing enum pending {:pending=&gt;0, :active=&gt;1, :suspended=&gt;2, :expired=&gt;3, :incomplete=&gt;4, :closed=&gt;5, :cancelled=&gt;6} Doing enum pending {:pending=&gt;0, :active=&gt;1, :suspended=&gt;2, :expired=&gt;3, :incomplete=&gt;4, :closed=&gt;5, :cancelled=&gt;6} Doing enum pending {:pending=&gt;0, :active=&gt;1, :suspended=&gt;2, :expired=&gt;3, :incomplete=&gt;4, :closed=&gt;5, :cancelled=&gt;6} Doing enum pending </code></pre> <p>(Over and over etc)</p> <p>As you can see, it's only seeing "pending"</p> <p>When I throw the inspected hash <code>{:pending=&gt;0, :active=&gt;1, :suspended=&gt;2, :expired=&gt;3, :incomplete=&gt;4, :closed=&gt;5, :cancelled=&gt;6}</code> into IRB and run <code>each</code> etc., it works just fine. What in all that is holy am I missing? </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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