Skip to main content
1 vote
1 answer
118 views

When using a Hash as a ERB templates, ruby complains about "encoding"

Simply to that require 'erb' a = "això és una merda <%=rand(1..20)%>" c = {"id" => "això és una merda <%=rand(1..10)%>"} If you run ERB.new(a).result, ...
somenxavier's user avatar
  • 1,607
-1 votes
1 answer
81 views

How can I convert an array to a hash that reflects the number of times each unique element in the array appears in the array?

Given an array I would like to create a hash whose keys are the unique elements of the array and whose values are the numbers of times the corresponding key appears in the array. For example, if the ...
Bob Kun's user avatar
  • 19
0 votes
1 answer
72 views

Add hash element to array in ruby script

I have ruby code which generate JSON of k8s images old_versions_json = "[]" versions_list = JSON.parse(old_versions_json) versions_list.push("#{namespace}") c = versions_list.find {...
Amey's user avatar
  • 1
-1 votes
4 answers
67 views

Accessing Nested Hash Elements in Ruby

I have an ruby array that looks like this. arr = [ { "dag"=>{ "tasks"=>[ { "arguments"=>{ "parameters"=>[ {...
Amey's user avatar
  • 1
0 votes
0 answers
36 views

Deep search for a value in a hash [duplicate]

I would like to analyze several hashes to extract certain specific information. These hashes have a global tree structure, however each of the branches of this tree structure is not always present in ...
h3lt3r-sk3lt3r's user avatar
1 vote
2 answers
640 views

Matching of randomly ordered array when test nested hash with RSpec

In my RSpec tests I often have the challenge to compare deep nested hashes like this { foo: ["test", { bar: [1,2,3] }] } The values [1,2,3] are read from a DB where the order is not ...
23tux's user avatar
  • 14.8k
0 votes
3 answers
71 views

Set two keys for one value in Hash in Rails

Let's say I have a hash: { first: :value1, second: :value1, third: :value2 } During .map I need to eliminate duplicates so it should be either first or second only. Is it possible to have some ...
unnamed_road's user avatar
2 votes
1 answer
131 views

Ruby Flattening JSON Objects or Hash in

// Flattening JSON Objects // (want to merge all keys as a string from nested hash and want out put in array list) input1 = {a: {b: {c: {} }, d:[] }, e: "e", f: nil, g: -2} input2 = {a: {b: {...
Gautam's user avatar
  • 84
0 votes
2 answers
160 views

Fetching all keys and values from a hash at once in Ruby

In **Ruby, I want to fetch all keys and values at once without needing to iterate through the hash. The keys are variables and the values of data type boolean. In the new Example, the only parameters, ...
cd4user's user avatar
  • 83
1 vote
3 answers
271 views

How to convert array to hash in Ruby using indices?

I want to convert the array of this: ["Cyan", "Magenta", "Yellow", "Black"] to hash like this: {1 => "Cyan", 2 => "Magenta", 3 => &...
Admiral Zukov's user avatar
0 votes
1 answer
169 views

How are equal hashes from multiple gitlab.rb files merged?

In a GitLab configuration file (gitlab.rc) an additional config file can be referenced: from_file "/home/admin/external_gitlab.rb" The documentation states the following: Any configuration ...
Roel Winter's user avatar
0 votes
1 answer
151 views

Js regex allow optional line break and space indentation

Some relative posts: Find whitespace in end of string using wildcards or regex Match linebreaks - \n or \r\n? let s = ` %nav.cf %ul.cf %li %a{ :href => "#" } ...
Weilory's user avatar
  • 3,177
0 votes
1 answer
53 views

How do I select a specific property in nested array json rails 5

I need help with this. I would like to access transactionCustomFields and I would like to get the token from the response. { "event":"TRANSACTION OUTCOME", "timestamp&...
Asher Namanya's user avatar
7 votes
5 answers
874 views

Generate a hash of all letters and digits

Using ruby, how do I make a hash of each letter in the alphabet (keys) and 1-26 (values) ? I need to create a hash with "a" to "z" in keys and 1 to 26 in values but I do not want ...
Aliénor's user avatar
0 votes
2 answers
479 views

How to properly escape Ruby hash to JSON for javascript JSON.parse?

I'm trying to embed a ruby hash into a json string that can be parsed by javascript JSON.parse. I'm having escaping issues. Ruby: props = {sring: 'He said "hey"'} HAML :javascript const ...
pixelearth's user avatar
  • 14.8k

15 30 50 per page
1
2 3 4 5
13