ruby

I have this JSON from the NHL API, and I tried to access the value gamesPlayed:
"teams"=>[
{
"id"=>5,
"name"=>"Pittsburgh Penguins",
"link"=>"/api/v1/teams/5",
"venue"=>{
"id"=>5034,
"name"=>"PPG Paints Arena",
"link"=>"/api/v1/venues/5034"...

require 'socket'
socket = TCPSocket.open('stream-api.betfair.com', '443')
while line = socket.gets
puts line.chop
end
socket.close
I should receive something like {"op":"connection","connectionId":"002-230915140112-174"}
but I receive Connection reset by peer which
betfair included a nodejs...

I'm not sure how to represent something like the following in a sequence diagram (in Ruby):
class FirstClass
def process
thing = SecondClass.new('string argument', third_class, 2)
end
def third_class
ThirdClass.new('another string argument',)
end
end
The first...

There are plenty of posts about the opposite way.
But how to I convert camelCase to camel-case in ruby? My regex-game is pretty low ... here is it the other way around:
def underscore(string)
string.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2')...

I'm trying to understand routes in Ruby on Rails and it's very hard to find the right info just by googling. So this is my question: what routes does the following snippet define ?
scope '/admin' do
resource :photo, :only => [:edit], :path => '/d/:domain_name', :domain_name =>...

I am trying to override one of the private methods of a gem only when certain conditions are met.
I would like to use this method only if a certain condition is met else use the gem's method.
module Net
class FTP
def makepasv
if condition
@sock.peeraddr[0] == 'AF_INET' ...

I'm new to Ruby on Rails. This question seems to be answered in other programming languages but not RoR.
I have an array with 3 items in it.
array1 = [1, 2, 3]
I then have items in another array which i want to check and see how many times array1 appear in array2:
array2 = [1, 2, 3, 4, 5, 6...

Help me. I don't understand how to fix it. I tried to many variations...
driver_iq_driver_spec.rb
describe '.perform' do
it 'correctly parse response' do
driver = described_class.new(dot_application, background_check_type, provider_setting).perform
expect(driver).to...

I'm trying to deploy my Rails app to Heroku and when I add the pg gem to my gemfile and run bundle install I get an error:
An error occurred while installing pg (1.1.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.1.3'` succeeds before bundling.
The bottom of my gemfile...

I ran the following Docker command from a Git Bash shell on Windows 10:
docker pull ruby:1.9.3
to get the following output (I removed a couple lines for clarity):
1.9.3: Pulling from library/ruby
...
Digest: sha256:c296bd581b8c1ee0585a77cafc0b14342356cea30a10fa2c9f82370909665149
Status: Image...

Is there a clean syntax to wrap link_to on html code based on condition? Because DRY, I don't want to repeat the same code.
<% if condition? %>
<%= link_to bla_bla_path do %>
<p>Some html here</p>
<% end %>
<% else %>
<p>Some html here</p>
<% end %>
I know there is link_to_if but it...

Given a hash with values containing arrays of unequal lengths,
{a: [1, 2, 3], b: [1, 2], c: [1]}
is it possible to create an array of hashes containing the same keys, of all permutations of single values like the following without resorting to nesting multiple loops?
[
{a: 1, b: 1, c: 1}...

I have been using the Ruby openssl module to decode information from a CSR.
I have the basic CSR decoded, but I cannot work out how to retrieve the Subject Alternate Names from the CSR.
Code so far:
require 'openssl'
def parse_csr(csr)
csr = OpenSSL::X509::Request.new csr
puts...

In a rental system, I have a model called Boardgame, with the attributes: name, copy and situation. Situation is another model, with belongs_to.
So an example of my database:
Catan, copy 1, available
War, copy 1, rented
War, copy 2, available
War, copy 3, rented
My code in the index view is...

I have 3 models with the following structure:
class Customer
has_many :invoices
has_and_belongs_to_many :locations
end
class Invoice
belongs_to :customer
end
class Location
has_and_belongs_to_many :customers
end
I'm trying to write a query that will grab invoices that have...

Frequently when I'm dealing with controllers I have found the need to stop the current action and then show an error page. Currently I have a method to show my error page in application controller:
class ApplicationController < ActionController::Base
def show_error msg
render file...

I am trying to implement the Draper gem for my Rails project and having trouble getting it to work. I'm getting the error message:
undefined method `exists?' for #Draper::CollectionDecorator:0x000055b625da7a10>
The error seems to be coming up from a partial I'm rendering on my index view. The...