1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# I executed this using irb

# I have a hash of actions and each value has both a :label and a :status,
# as follows:

irb(main):002:0>   actions = {
irb(main):003:1*     'repair' =>  { :label => 'Repair', :status => 'broken' },
irb(main):004:1*     'brake'  =>  { :label => 'Brake It', :status => 'working' },
irb(main):005:1*     'dismiss' => { :label => 'Brake It', :status => 'working' }
irb(main):006:1>   }

=> {"repair"=>{:status=>"broken", :label=>"Repair"}, "brake"=>{:status=>"working", :label=>"Brake It"}, 
"dismiss"=>{:status=>"working", :label=>"Brake It"}}

# Here is one example of what my current status can be
irb(main):007:0>   my_status = 'working'
=> "working"

# So I want to get a hash with all the possible actions I
# can execute, given the status I'm on
irb(main):008:0>   my_actions = actions.select { |k, v| v[:status] == my_status }
=> [["brake", {:status=>"working", :label=>"Brake It"}], ["dismiss", {:status=>"working", :label=>"Brake It"}]]

# my hash was transformed into an array of arrays, so let's try to access some members:
irb(main):011:0> my_actions.map {|item| "action: #{item[0]} - label: ${item[1][:label]}"}
=> ["action: brake - label: ${item[1][:label]}", "action: dismiss - label: ${item[1][:label]}"]

# Why item[1][:label] was not expanded