Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
3 votes
3 answers
115 views

Fill or complete a hash in ruby with all sibling keys

I have a rails API where I'm able to query vehicles and count and group by different attributes. I would like to fill the response with zero values when a group by is used. Here is a simple example: ...
TobiasKnudsen's user avatar
0 votes
0 answers
52 views

How to avoid deleting backslash in Node.js

I have to verify signature that created by Ruby service. The signature is creating from stringified JSON data. The problem is that if data contains single backslash in nested strings then Node.js ...
Hüseyn's user avatar
  • 15
0 votes
0 answers
148 views

MySQL - How to generate a hashing password with salt in caching_sha2_password format

In MySQL 5.7, I used to create a hashing password in Ruby by def generate_mysql_password(plaintext_password) digest = OpenSSL::Digest.new('sha1', OpenSSL::Digest.new('sha1', plaintext_password)....
binhdt2611's user avatar
0 votes
1 answer
53 views

If hash is nil, how to set the key?

I'm storing a book object in a Hash using its title as the key. If the book's already in the hash, I'm calling another method, so I do a check to see if it's in the hash using the key? method. However,...
Leahcim's user avatar
  • 41.2k
1 vote
2 answers
112 views

Why isn't if condition to check if a hash[key] is set to a value of true (boolean) isn't working as expected?

I have the following nested hash called cars {:honda=>{year=>2008,is_condition_good?=>true}, :toyota=>{year=>2010,is_condition_good?=>false} } I want to return the nested hash that ...
Aerobu's user avatar
  • 11
0 votes
1 answer
41 views

Convert string to nested Ruby Hash [] get method

I have a string like '[field1][field2]' that I need to use to access a nested field from a Hash object. Basically, I want to do hash_obj['field1']['field2']. How can I transform that string to ...
Pedro's user avatar
  • 1
2 votes
1 answer
146 views

Difference between tap / delete and except in Ruby Hash

I am facing a very curious behavior. This is Ruby 2.6.6, so a block hash variable in a loop isn't frozen. In this example, source is frozen. Doing this: result = source.tap { |s| s.delete(:key) } ...
Ruby Racer's user avatar
  • 5,740
1 vote
3 answers
101 views

Merge n dimensional hashes and sum values in ruby

I'm trying to implement a logic to merge n dimensional hashes in ruby. In case they have identical key I'm looking for a sum of their values I have a method that on each iteration returns a hash like ...
user3266359's user avatar
0 votes
0 answers
79 views

C++ to Ruby: Equivalent hash of a string as in C++

My C++ code creates a hash of a string using the standard functional library. I would like to port this function to Ruby, but as you can see, I lay my hashing into the strong, mighty hands of the C++ ...
Alex's user avatar
  • 368
-2 votes
1 answer
52 views

Insert hash values into another hash in ruby without outer parentesis [duplicate]

I have the following data structure in one of my templates: [ { geometry: { type: geometry, coordinates: coordinates }, } ] and then i have an options-hash that looks like this: ...
Bergrebell's user avatar
  • 4,580
0 votes
1 answer
48 views

Just started learning Ruby; Why does my code work properly in the Codeacademy environment but not in the Mac Terminal?

Completed a mini project on Hashes & Symbols, and wanted to see how it ran in the terminal. It executes perfectly in Codeacademy, but in the terminal it's printing out the wrong responses, ...
maximusmd's user avatar
1 vote
1 answer
52 views

convert to JSON in Ruby

I have the following lines in a text file and iterate using File.foreach. I want to create a JSON format of these. How do I code that? As I print the hash, the Camaro overwrites Mustang info. #...
Jake Statefarm's user avatar
0 votes
1 answer
87 views

Why is HackerRank's Sample Test cases throwing a NoMethodError at the Ruby #tally method in my code?

I've attempted to solve this HackerRank Sparse Arrays problem with Ruby. I wanted to use #tally on the string_list array in order to create a hash of keys and their occurrence count. I have checked ...
Robert L.'s user avatar
0 votes
1 answer
74 views

Failing to verify existing password hashes with ruby BCrypt

I'm currently running into an issue trying to implement an authentication on Ruby on Rails against an existing database with existing password hashes. I do have a couple of existing plaintext ...
Benjamin Scharbau's user avatar
0 votes
2 answers
85 views

Why does && operator not work inside a hash block but and operator does?

Given the following hash hash = {a: 5, b: 10} I want to check if all values are Integers and < 10. hash.all?{|key,value| value.is_a? Integer && value < 10} ## TypeError: class or module ...
pinkfloyd90's user avatar

15 30 50 per page
1
2 3 4 5
287