Questions tagged [ruby-hash]

The Hash class is a Ruby's variant of a dictionary or associative array. Contrary to arrays, the key type of a Hash can be of any type. For questions regarding (cryptographic) hashing, use the [hash] tag.

For more information specific to ruby hash, see the documentation here.

188 questions
-2
votes
1 answer

How to use values of a hash dynamically?

Goal: Use unique email address in email header To: field (see message_class) of MIME Html Message. File: database.rb Here I connect to the database and I loop through the rows in table rcpt. Then I store the value in row["email"]. require…
Peter
  • 13
  • 7
-3
votes
1 answer

How do I iterate over this Hash in Ruby?

[:sha,"string"] [:node_id,"dsd"] [:stats,{:total=>122},:additions=>23],:deletions=>72}] [:files,[{:sha=>"456"},:filename=>"456"],{:sha=>"123"},:filename=>"123"]] I want to access the content of files sha and stats. …
C-mmon
  • 43
  • 7
-3
votes
1 answer

How to extract all values from a key that are inside a hash

I ask a user for input, and store it as hashes inside an array. I need to extract the values that share the same key from those hashes. I want to print the names of students that belong to the same cohort like this: "May cohort students are: Brian,…
codeanth
  • 1
  • 2
-3
votes
1 answer

How to convert '{"key1" => "value1", "key2" => "value2"}' to '{key1:"value1", key2: "value2"}'

I want to convert from: {"key1" => "value1","key2" => "value2"} to {key1: "value1", key2: "value2"}
Manoj Kumar
  • 316
  • 1
  • 7
-3
votes
2 answers

manipulate ruby hashes to generate data series

I have hash from code like this below {"Jan 2016"=>4649, "Feb 2016"=>3945, "Mar 2016"=>4870, "Apr 2016"=>4872, "May 2016"=>6494, "Jun 2016"=>4981, "Jul 2016"=>9949, "Aug 2016"=>4842, "Sep 2016"=>5820, "Oct 2016"=>4934, "Nov 2016"=>4136, "Dec…
widjajayd
  • 6,090
  • 4
  • 30
  • 41
-4
votes
1 answer

Array of arrays with headers to array of hashes(and then JSON)

How can I convert array of arrays (CSV-liks with headers) to an array of hashes ? headers = [['foo', 'bar', 'baz']] data = [[1,2,3], [4,5,6], [7,8,9]...] arr_of_arrs = headers + data arr_of_arrs_to_structured_hash expected output be like [ {foo:…
Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164
-4
votes
2 answers

Read multiple hash at a time and update the values in Ruby

Consider the variables: ctr = ['cobol',nil,nil,'test',nil,'cobol', nil] h1 = { 0=>{"ABC"=>"10000100126N", "CDE"=>"2013-08-30-}", "TPP"=>"11400000206633458812N", "APD"=> "01531915972", "PRODUCTID"=>"113n", "OPP"=>"201509n", "CTC"=>"C"},…
s c
  • 71
  • 1
  • 11
-7
votes
5 answers

Is there a way to convert this array to a hash without the inject method?

animals = [['dogs', 4], ['cats', 3], ['dogs', 7]] Convert animals to: {'dogs' => 11, 'cats' => 3}
CJ Jean
  • 971
  • 1
  • 8
  • 10
1 2 3
12
13