1
vote
7answers
71 views

Removing all elements of a column in a two-dimensional array

I have this array: arr = [["a","b","c"],[2,3,5],[3,6,8],[1,3,1]] which is representing a prawn-table containing columns "a", "b", and "c". How do I remove the entire column "c" with all its ...
-1
votes
1answer
90 views

Flatten a nested hash in Ruby on Rails

I have a hash in the structure below { "Result": [ { "Links": [ { "UrlTo": "http://www.example.com/", "Visited": ...
3
votes
4answers
70 views

Slice array when element reached

Lets say I have an array like so: ['x','cat', 'dog', 'x', 'dolphin', 'cougar', 'whale'] I don't know the length of the array or when an 'x' will occur. When I reach 'x' I want to push the following ...
2
votes
5answers
84 views

How do I add a cumulative sum to an array for only one value?

I have an array of arrays with x and y values: [[some_date1, 1], [some_date2, 3], [some_date3, 5], [some_date4, 7]] The result should only sum the y values (1, 3, 5, 7) so that the result is like ...
0
votes
1answer
74 views

Array of Arrays sum in ruby

arry = [["a",3.0,3], ["b",4.0,4], ["c",5.0,5]] I am looking for the following output [["a", 3.0, [["b", 4.0, 7], ["c", 5.0, 8]]], ["b", 4.0, [["a", 3.0, 7], ["c", 5.0, 9]]], ["c", 5.0, [["a", ...
1
vote
1answer
50 views

Sorting multidimensional array, descending

I have an multidimensional array in my ruby which looks like this : arr= [{"10.0.1.50", "4"}, {"10.0.1.51", "10"}, {"10.0.1.48", "7"}] I want to sort it such that the result should be: ...
-2
votes
2answers
65 views

Ruby: create a double array from string based on a colon separator

I get a string with the following repeating pattern: label (one word), colon, some text (pretty much anything, even empty). For example: "FileSize: 597262388 Duration_String: 1h 34mn ...
0
votes
3answers
93 views

Multi-Dimensional Array in Ruby on Rails?

I'm wondering if its possible to do multidimensional arrays in rails? I'd like to get something like to formulate some data: apple => 'tasty', 'red', 'round' cereal => 'milk', 'breakfast' name ...
0
votes
2answers
43 views

ruby array of arrays saving data across all insances of array, euler 18

for the following code #!/usr/bin/ruby -w nums = File::read("euler18nums.txt"); #opens file with number array inside. parts = nums.split(' '); #save it into instance of an array. t ...
2
votes
5answers
104 views

How to get specific value within an array of arrays

I have an array (outside array) that contains three arrays (inside arrays), each of which have three elements. array = [[a, b, c], [d, e, f], [g, h, i]] I want to select the specific inside array ...
2
votes
2answers
59 views

Ruby unpack array to block

settings = [ ['127.0.0.1', 80], ['0.0.0.0', 443] ] How can I do: settings.each do |ip, port| ... end Instead of: settings.each do |config| ip, port = *config ... end
2
votes
1answer
50 views

.each seemingly recursing into second dimension of 2D array

I have just stumbled upon this way of iterating over 2-dimensional arrays in Ruby: [[1, 2], [3, 4]].each {|x| puts x} The output is: 1 2 3 4 My question is simple: why and how is this happening? ...
1
vote
4answers
119 views

How to make Ruby hash of arrays from array

I'm a Perl developer trying to learn Ruby... So, I'll demonstrate in Perl what I'm trying to accomplish in Ruby and then summarize at the end... #!/usr/bin/perl -w use strict; use Data::Dumper; # ...
0
votes
2answers
31 views

How to access assoc array within assoc array

I have the following code: def operation hash puts hash[:three][:three][:three] end operation :one => 'item', :two => [1,2,3], :three => [ :one => 1, :two => 2, :three ...
-2
votes
1answer
85 views

Ruby Variable Index in 2D Array [closed]

I have a two dimensional array right now that I'm attempting access and save into an object. For some reason I keep getting this error: "undefined method '[]' for nil:NilClass (NoMethodError)" ...

1 2 3 4 5 9
15 30 50 per page