Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [ruby]

Ruby is a multi-platform, open-source, dynamic, object-oriented, interpreted language created by Yukihiro Matsumoto (Matz) in 1993.

0
votes
0answers
9 views

Making a certificate signing request, with validation

I have a function that takes a handful of parameters and I want to ensure the data being passed to it is the correct data and types. Below is a sample function that I wrote to ensure the parameters ...
3
votes
1answer
43 views

Game of Life in Ruby

I think Ruby is kinda interesting, so did this Game of life implement in Ruby. I am wonder is there is some magic in Ruby can let my code more elegant. I am a python coder and I think my Ruby kinda ...
1
vote
0answers
18 views

Use of inheritance using two Ruby libraries

Currently I'm working on parsing data from a form service into a pdf form. I created 2 classes one inheriting from the other one. However, I see that the classes I created are growing in lines of ...
0
votes
1answer
23 views

Non-recursive factorial in Ruby

I've implemented a factorial function in a more "Ruby" way. I would like to get feedback on the algorithm. ...
0
votes
0answers
28 views

Parking lot system design

Problem Statement I own a multi-story parking lot that can hold up to 'n' cars at any given point in time. Each slot is given a number starting at 1 increasing with increasing distance from ...
1
vote
0answers
20 views

A Ruby on Rails controller and JS code to add labels to products, like Gmail's labeling tool

My friend asked me to write a tool that lets users bulk add/edit labels (taxons) to store (spree commerce) products. I came up with this, curious to know if you guys find the code readable/...
1
vote
1answer
39 views

Showing a message when the column is true

I'm making an app using Rails. I have 4 Boolean columns in a table like below, and I want to show a message if that column is true. ...
2
votes
1answer
16 views

Offset vs Cursor Pagination

I am trying to compare any performance gain(s) from moving a current offset-based pagination endpoint to a cursor based one. I have the following ruby code: ...
0
votes
0answers
12 views

Connecting to DB2 using Ruby on Rails

I need to connect to a IBM db2 table using jruby and Ruby on Rails. I have managed to do it, but I haven't seen this solution anywhere and I am hoping I can get some feedback on it, or if there is a ...
1
vote
2answers
34 views

Knapsack class in Ruby

This is a simple implementation of a knapsack written in Ruby. I've included all the relevant code here, but my question is concerning the contents setter ...
1
vote
2answers
32 views

Partition array to hash in ruby

Problem: convert this array of hashes: ...
0
votes
0answers
21 views

Join model that constantly has to reference parent(s)

I have a situation where there are restaurant dishes that can be served at many different locations. An example would be somewhere like McDonalds where the Big Mac is served at locations nationwide. ...
1
vote
1answer
29 views

case…when or Hash#fetch [closed]

I have the following method, which can be written in the following two ways: which one would you prefer, and why? ...
1
vote
2answers
47 views

Whiteboarding - Multiply all values in array except at the index for each

Consider this interview question: You have an array of integers, and for each index you want to find the product of every integer except the integer at that index. Write a method ...
2
votes
1answer
65 views

Rails thin controller method to change account plan and fire slack message via a service object

I'm a beginner with Rails and am trying to figure out how to keep my controllers clean and thin, and how to work with service objects. I am building an internal tool to manage our SaaS customers, and ...
1
vote
1answer
39 views

Efficiently determining maximum allowed euclidean distance between lists of colors

I was recently tasked with determining which hex RGB colors in list color_list are nearest to each hex RGB color in list target_colors, using euclidean distance as the measuring stick, and only ...
1
vote
0answers
34 views

Ruby - Create a bitmap editor that accepts user input to plot a matrix grid, points and lines

I recently didn't pass a take-home code test for a job interview - and one of the reasons for this was that the code was not as idiomatic as it could be. The premise is in the title - but below ...
0
votes
1answer
28 views

Pyramid of doom Grape endpoints

I'm creating an API endpoint to create and delete associations, essential creating and deleting records of a join model. The code below doesn't seem idiomatic or pragmatic at all. What's the best way ...
1
vote
1answer
54 views

Short Ruby program that opens a random video file from a directory

I am currently learning to code in ruby. I have created a small program that iterates through a directory of video files and opens one at random. The program is fully functioning (with the odd issue). ...
0
votes
1answer
34 views

Trie structure using Hash in Ruby

This is a follow-up to Boggle board solver in Ruby ...
4
votes
2answers
65 views

Boggle board solver in Ruby

The following is my attempt at creating a Boggle board solver in Ruby. It's not especially fast. I would love to have input on how the solution can either be sped up, or whether a different algorithm ...
1
vote
0answers
44 views

Script to auto-generate Markdown tables of content

I would greatly appreciate feedback on the enclosed script, which auto-generates a Markdown table of contents for Github-flavoured Markdown, with respect to: Consistency with Ruby idiom & style ...
2
votes
2answers
52 views

Modelling football teams and fixtures in Ruby (as compared to SQL)

I am trying to model information around football teams and fixtures. I am using the Premier League fantasy football API for my data. The fixtures API is here, and the team data (along with a lot of ...
1
vote
0answers
33 views

Simple ruby program for AWS ruby SDK

I wrote a simple ruby program for interacting with one of my temporary AWS S3 using Ruby SDK. Below is the program I've written. Since I learned ruby by myself I need help/suggestions in following ...
2
votes
0answers
64 views

Drawing an ASCII grid in Ruby based on a 2D array

I'm writing a function that renders a grid using ASCII line-drawing characters, based on a provided 2D array (or array of arrays), with each top-level array representing a row, and the items inside ...
2
votes
1answer
107 views

RuboCop: parameter list too long in initialize method

I have an initialize method for a class that looks like this: ...
3
votes
1answer
72 views

A Ruby script to generate random “people”

I'm working on developing a small Ruby program to generate random data for a Neo4J database, including people, addresses, phone numbers, etc. I'm a total beginner to Ruby, so I wanted to post my ...
0
votes
1answer
24 views

Ensure that a Sinatra hash always has a valid value

I'm trying to ensure that a Sinatra hash always has a valid value. Is there a more-concise way to write this? ...
3
votes
0answers
74 views

Implementing secure API for use between other internal apps

My team and I are trying to implement a secure API and would appreciate some feedback on the following: If there are areas of improvement in the current code to improve security Recommendations on ...
1
vote
1answer
56 views

Creating an associated object on create/update

My app is setup where there are musical artists and albums have message boards through a has_one polymorphic association. ...
3
votes
0answers
90 views

Retrieving data from the movie database

I am trying to retrieve the series, seasons and episodes from the movie database, however I am pretty new to Ruby on rails and I feel like what I am doing could be improved a lot. I use an ...
1
vote
0answers
142 views

Ruby Hash to XML

I've just made this "serialization" module in Ruby that takes a hash and outputs a XML string. ...
6
votes
2answers
145 views

Calculate Hamming distance between DNA sequences in Ruby

I am requesting a review for my solution to this problem from exercism.io. I'm posting it here since there is not always input on solution submitted through exercism. The problem is as stated: ...
2
votes
2answers
87 views

Rails controller for a vocabulary quiz

I'm new to refactoring and I have just refactored an old Rails project that had bloated controller methods. I spun off the bloated methods into its own separate controller following this logic, since ...
0
votes
0answers
28 views

Creating join table entries based on different connection ids

My controller code is: I'm using callbacks to find @lead. ...
0
votes
0answers
15 views

Grab and kill AMQP subscriber

I am using amqp client in order to get data. I am using sidekiq jobs in order to make sure that client is always connected and getting data. ...
2
votes
2answers
43 views

Distinguishing between people who have likes to posts and those who have dislikes

I want to distinguish between people who have likes to posts and those who have dislikes. I want to find a way to improve my code without thinking it is efficient. ...
1
vote
2answers
46 views

URL Routing Application

In a Ruby on Rails application I want to have this routing: for URL www.example.com/reports go to controller documents and action ...
0
votes
2answers
115 views

Ruby on Rails application controller

My application controller keeps growing with small helper methods that I use in both my controller and views, is it okay? or what do you recommend doing? ...
3
votes
1answer
28 views

Ruby Regex to update various variables inside a file

In our applications we have a version file that has three variables that are then joined to create a string that can be used for the semantic version. The file looks like: ...
2
votes
0answers
55 views

Counting how many questions in each category are tagged

I have a homepage that shows how many questions are in a certain category which is done through tagging. The functionality is working great, it tells me how many of each there are. However, newrelic'...
0
votes
0answers
32 views

Rails db query to pull joined and included data

I have a conversations controller which is used to pull all the conversations for a user of type seller. Sellers can have <...
3
votes
1answer
100 views

Ruby getter recursively builds tree

This is a getter in a class. It recursively generates a tree/hash to a certain level of depth. ...
3
votes
1answer
84 views

Model Association (Rails 5 API)

I have a Character model that has a CharClass and ClassPerks child. Currently I am ...
0
votes
0answers
39 views

Simple Rate Limit Utility Class written in Ruby

I have the following simple rate limit utility class written in Ruby. Its function is quite simple and works for my intentions. It uses a class variable to manage/share all timestamps across my ...
0
votes
0answers
48 views

Rails view to display optional text

I have been using rails for a little while now and have read a few articles that talk about removing as much logic from your controllers as possible. I have a maps object with the following schema. ...
3
votes
1answer
53 views

Creating a Basic Success Function for Http

I got sick of every time I make an Http request validating that the response was a success. I did a lot of: if response.class == Net::HTTPOK or ...
1
vote
3answers
101 views

Calculate cryptocurrency gains and losses using the Coinbase API

This class calculates the gains and losses (in USD) from the four leading cryptocurrencies using the Coinbase API. (The full repo can be found here) In addition to general feedback there are some ...
3
votes
2answers
163 views

Validating IBAN in Ruby

Looking for tips on how to improve my code and areas that I can better follow Object Orientated principles. Is this class structure ok? How is the code overall? The problem: There are two IBAN ...