Questions tagged [ruby-1.8.7]

For issues relating to developing in Ruby, version 1.8.7.

Use this specific tag along with the generic one: .

203 questions
-1
votes
2 answers

How to get an average from matrix[array]

(Before start, I am using Ruby 1.8.7, so I won't be able to use fancy stuff.) As title says, I want to calculate the average of column or row. But, I can't even find the way to traverse/iterate Matrix form of array from online. Let's say you have…
GothLoli
  • 19
  • 1
  • 6
-1
votes
3 answers

regex to match everything except protocol from url

I have the following regex pattern: (?:http.?:\/\/) This matches the protocol component from a web url, I want a regex to do the opposit, to match everything except the protocol, so far my every attempt has not worked at all. Becuase ultimatly what…
Thermatix
  • 2,757
  • 21
  • 51
-1
votes
3 answers

Inject in array

I am trying to do some calculation like the following. option is an empty hash and aes is an array. options = {} aes = [1,2] test = aes.inject([]) do |array, value| array << value + 2 array << value -1 if options[:calculation] # here…
Arvind Kumar
  • 237
  • 3
  • 11
-1
votes
1 answer

Greedy conditional algorithm

I have a list of k artistes mapped to their respective music videos that they have starred in. This is represented in a multidimensional array: musicvid_arr = [["MUSICVID 1", 2014, ["ARTISTE 1", "ARTISTE 2", "ARTISTE 3"]], ["MUSICVID 2", 2014,…
JQuack
  • 21
  • 4
-1
votes
1 answer

Array of IDs to array of function results

I currently have this code def objects(ids) array = [] ids.each do |id| array << object(id) # => # end array end objects([1, 2, 3]) # => [#, #, #] It seems like there should be a cleaner way to…
Dan Grahn
  • 9,044
  • 4
  • 37
  • 74
-1
votes
2 answers

Ruby: Permutation on an Array

Say, I have an array: a = [1,2] and n = 3 I want output like this: [[1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 2, 2], [2, 1, 1], [2, 1, 2], [2, 2, 1], [2, 2, 2]] This are all possible combinations of length n of elements from array a. Most importantly…
rony36
  • 3,277
  • 1
  • 30
  • 42
-1
votes
1 answer

Sorting a ruby hash with underscore in keys

I usually sort ruby hashes using the very famous sort method as given in my example below. But this terribly fails when the string key has an underscore in it. For eg: h = {"b" => 1, "a" => 2} Hash[h.sort] sorts the hash perfectly. But when the…
Aravind
  • 221
  • 4
  • 13
-2
votes
2 answers

adding a new table using rails migration..?

I want to add new table using rails migration: **table_name** users_location_track **columns** id (primary key, auto increment serial), user_id (reference to users), location_info (string), creation_time(time-stamp) please…
piyushmandovra
  • 4,219
  • 3
  • 19
  • 30
1 2 3
13
14