All Questions
553 questions with no upvoted or accepted answers
8
votes
1
answer
835
views
Rails Strong Parameters - allow deep nested hashes within array
How to permit/white-list deep-nested hashes with very un-regular (impossible to declare) structure.
Example:
{"widgets" => [
{
"id" => 75432,
"conversion_goal_id" => 1331,
"...
7
votes
2
answers
526
views
Count items in arrays cross 100's of thousands of records
I have a Rails app with a Postgres database that has an Artists table with a jsonb genres column.
There are hundreds of thousands of rows.
Each genre column in the row has an array like ["rock", "...
5
votes
2
answers
311
views
Is there a more lightweight alternative to array?
I need to create an array with 3 billion boolean variables. My memory is only 4GB, therefore I need this array to be very tight (at most one byte per variable). Theoretically this should be possible. ...
4
votes
0
answers
202
views
What changes need to do to work with rails 7 without postgres_ext
I am maintaining a rails 4.2.11 project and using postgres_ext as a dependency. Now as we are planning to update to rails 5 and higher. I noticed that postgres_ext is not maintained anymore and will ...
4
votes
0
answers
101
views
Ruby array element evaluation
I like to know why in arrays when an element is a method call the existence of parentheses matters. I understand [] is a method call and I assumed the arguments to that method call would be evaluated ...
4
votes
3
answers
145
views
How to write a ruby method that returns a count of items that are alike in two arrays but in different positions
I am trying to code a version of the game Mastermind in Ruby. To do this I need to write a method that will return a count of how many elements two different arrays have in common but are at different ...
3
votes
0
answers
258
views
How to set an array contains value condition with Ruby Sequel?
I have this function that I need to modified to select from elements table the rows in which the column filters(array type) contain the feature_id param
def get_categories_by_company_and_feature(...
3
votes
1
answer
91
views
Removing 'nil's from a column using transpose
I have a nested array:
arr = [[1,nil,2,3,4], [2,nil,4,5,6], [6,nil,3,3,5]]
Any elements at the same index in the subarrays that are nil across the array must be removed. The second index in all ...
3
votes
1
answer
1k
views
Rails 4 - Saving multiple value in JSON objects in one single form AND/OR
This table is tbl_notification. Let say, I want to produce a JSON output something like this:-
[
{
"trigger_event":"ONE",
"ptc":
{
"id":"184"
},
"message":"this is message"...
3
votes
1
answer
156
views
How to separate brackets in ruby?
I've been using the following code for the problem. I'm making a program to change the IUPAC name into structure, so i want to analyse the string entered by the user.In IUPAC name there are brackets ...
3
votes
1
answer
105
views
Keeping a C array and a Ruby array in sync using an extension?
I'm writing a C extension in Ruby, and I'm running into a bit of a problem. I have a couple of C structs, here's a simplified version:
typedef struct
{
int score;
} Player;
typedef struct
{
int ...
3
votes
0
answers
991
views
[].include?(:test) return nil
Having the strange problem that [].include?(:test) returns nil instead of expected false. The whole thing only happens when running the app (i see it in rubymine debug mode), not in irb or rails ...
3
votes
3
answers
198
views
Recursively setting hash keys from an array of keys
I want a function that can take an array like [:a, :b, :c] and recursively set hash keys, creating what it needs as it goes.
hash = {}
hash_setter(hash, [:a, :b, :c], 'value')
hash #=> {:a => ...
2
votes
0
answers
66
views
Has Array#sort become stable?
From the docs
"When the block returns zero, the order for a and b is indeterminate, and may be unstable:
a = 'abcde'.split('').shuffle
a # => ["e", "b", "d", &...
2
votes
7
answers
2k
views
How to loop 2D array in a anti-clock wise fashion?
Given a 2D array of m x n dimension, how can I loop through them in anti-clockwise fashion?
For example:
matrix = [
[ 1, 2, 3, 4 ],
[ 5, 6, 7, 8 ],
[ 9, 10, 11, 12 ...