Run multiple commands in the same shell process

I'm attempting to run a series of commands through Ruby, and capture stdin, stdout, stderr and the exitstatus. require "open3" require "pp" command_list = [ "export MY_ENV_VAR=foobar", "printenv MY_ENV_VAR" ] executed_commands = [] result = ni...
more »

2017-06-15 22:06 (2) Answers

Rails server not working after changing gemfile

After I changed my Gemfile in rails and ran bundle install and update, I tried to run the rails s but then I got this error: C:\Users\alouf\Sites\fapp>rails s C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x64-mingw32/lib/bcrypt.rb:16:in `r...
more »

2017-06-15 22:06 (0) Answers

Ruby - Can't find a string in a txt file

I'm writing a code to search a string in all txt files of a directory. The code works ok in 2 of of 3 files. search = ['first', 'second', ...] Dir["directory/*.txt"].each do |txt| file =, encoding: "ISO8859-1:utf-8") search.each...
more »

2017-06-15 20:06 (2) Answers

Using splat operator with when

Case statement: case x when 1 "one" when 2 "two" when 3 "three" else "many" end is evaluated using the === operator. This operator is invoked on the value of the when expression with the value of the case expression as the argument. The ca...
more »

2017-06-15 10:06 (1) Answers

Issue with mongify check database.config

I am running the command: mongify check database.config But I am getting this error: C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'mys...
more »

2017-06-15 09:06 (0) Answers

How to merge two array objects in ruby?

If I start with two arrays such as: array1 = [{"ID":"1","name":"Dog"}] array2 = [{"ID":"2","name":"Cat"}] How to merge this array into one array like this? arraymerge = [{"ID":"1","name":"Dog"}, {"ID":"2","name":"Cat"}] ...
more »

2017-06-15 02:06 (4) Answers

"Buying a car" Ruby codewars

I am trying to do Ruby codewars challenge and I am stuck since I pass sample tests but can't pass final one. I am getting error Expected: [8, 597], instead got: [8, 563]. Instructions : A man has a rather old car being worth $2000. He saw a...
more »

2017-06-15 02:06 (2) Answers

Scrape an entire API or rely heavily on it?

I'm building a resort review site in rails. Currently, a User has many reviews, and each Review belongs to a User. The reviews table contains an expedia_id field. All data - the hotel name, images, description, etc. are pulled dynamically from the ...
more »

2017-06-14 21:06 (1) Answers

ruby set isn't unique

For some reason the following code produce a set with duplicate values. I'm not sure how uniqueness of an array in ruby is defined so maybe this is somehow expectable? require 'set' xs = [1, 2, 3] xss = [] xs.each do |x| xss.merge xss.to_a...
more »

2017-06-14 10:06 (1) Answers

Gateway Error on Spree

I have just integrated the gateway into the spree, I have already set the API and Encryption keys, however, whenever I try to make the payment, it does not complete and the following error occurs: Gateway Error ---! Ruby / object: ActiveM...
more »

2017-06-14 00:06 (0) Answers

2 field validation in Hanami + dry-validation

I've been trying to validate a sign in process using Hanami (which is on top of dry-validation). The point is: how to validate someting related to 2 fields: email + password? I've read about custom predicates, but they seem to be only per field. An...
more »

2017-06-13 18:06 (1) Answers

Adding Hashes from an array

I am trying to create an array/hash from an array of multiple hashes with same keys and an average of values. My array: [{:amount=>897500, :gross_amount=>897500, :tax=>147500, :hotel_fees=>0, :base_fare=>750000, :currency=>"INR"}, ...
more »

2017-06-13 17:06 (4) Answers

Correct semantic usage of map

I am trying to understand what is a semantically right way to use map. As map can behave the same way as each, you could modify the array any way you like. But I've been told by my colleague that after map is applied, array should have the same orde...
more »

2017-06-13 17:06 (2) Answers

When to load Gem code when depending on rails

I'm developing a Gem that is to be used exclusively in Rails projects. It has been developed inside of a Rails application's lib directory and is now to be extracted in a separate Gem. Some of the classes depend on the Rails framework to be loaded t...
more »

2017-06-13 10:06 (1) Answers

Ruby: Reference the currently executing block

Is there any way to reference the currently executing block in Ruby for one-off recursion? For example, to perform a "deep" merge on Hashes: hash1.merge(hash2) do |k,o,v| (o.is_a?(Hash) && v.is_a?(Hash)) ? o.merge(v, &CURRENT_BLOCK) : ...
more »

2017-06-12 17:06 (1) Answers

splite date with Ice_Cube in rails

I want to create an Api that it get start_time and end_time and the number of month that should split start time and end time and return a collection that i can loop through that and save the data in to the database. for example every week from 14:05...
more »

2017-06-12 13:06 (1) Answers