Add values to multiple keys in one line I Have orders table, every order has different payment method and made by different user, has different total of money.

and i want to make a detailed report, i export date as a hash to the views, as follow : 

orders = Order.where(state: 'paid').settled(false).order(showtime: 'ASC')

my_hash = {
  users: Hash.new { |h, k| h[k] = {
    showtimes: Hash.new { |h, k| h[k] = {
      movies:  Hash.new { |h, k| h[k] = {
        payment_methods: Hash.new { |h, k| h[k] = Hash.new(0) },
        total_cash: Hash.new(0), total_credit: Hash.new(0) } },
      total_cash: Hash.new(0), total_credit: Hash.new(0) } },
    total_cash: Hash.new(0), total_credit: Hash.new(0) } },
  total_cash: Hash.new(0), total_credit: Hash.new(0) };

orders.each do |o|
  user = o.user.name
  showtime = o.showtime.strftime('%m-%d %H:%M')
  movie = o.movie.name
  payment_method = o.payment_method

  my_hash[:users][user][:showtimes][showtime][:movies][movie][:payment_methods][payment_method][:tickets] += o.t_count
  my_hash[:users][user][:showtimes][showtime][:movies][movie][:payment_methods][payment_method][:money] += o.m_total
  my_hash[:users][user][:showtimes][showtime][:movies][movie][:total_cash][:tickets] += o.t_count
  my_hash[:users][user][:showtimes][showtime][:movies][movie][:total_cash][:money] += o.m_total
  my_hash[:users][user][:showtimes][showtime][:total_cash][:tickets] += o.t_count
  my_hash[:users][user][:showtimes][showtime][:total_cash][:money] += o.m_total
  my_hash[:users][user][:total_cash][:tickets] += o.t_count
  my_hash[:users][user][:total_cash][:money] += o.m_total
  my_hash[:total_cash][:tickets] += o.t_count
  my_hash[:total_cash][:money] += o.m_total
end


is there a better way, with less number of lines, can i fill the hash in one line every loop ?
I haven't tested this but you should be able to do something like:

my_hash = Hash.new { |h, k|   
  if k == :total_cash
    h[k] = Hash.new { |h, k| h[k] = Hash.new(0) }                           
  else
    h[k] = Hash.new(&amp;h.default_proc) 
}


Other than that, I think it would be easier to read if you reorder it a bit:

my_hash = {
  total_cash: Hash.new(0), total_credit: Hash.new(0), 
  users: Hash.new { |h, k| h[k] = {
    total_cash: Hash.new(0), total_credit: Hash.new(0) },
    showtimes: Hash.new { |h, k| h[k] = {
      total_cash: Hash.new(0), total_credit: Hash.new(0) },
      movies:  Hash.new { |h, k| h[k] = {
        total_cash: Hash.new(0), total_credit: Hash.new(0) },
        payment_methods: Hash.new { |h, k| h[k] = Hash.new(0) }
      }
    }
  }
}