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
12 views

Ruby: Will pessimist lock (self.lock!) work using update_all? [closed]

I don't want to use save! method, will pessimist lock (self.lock!) work using the update_all method? ...
-2
votes
0answers
11 views

Will optimistic locking work for following code using updated_at attribute in update_all? [closed]

Product model Can be updated by multiple users. However, at a time only one user should able to update. For that, I want to use optimistic locking for Product model ...
1
vote
1answer
28 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
29 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
24 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
43 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
29 views

Trie structure using Hash in Ruby

This is a follow-up to Boggle board solver in Ruby ...
4
votes
2answers
58 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
37 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
45 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
29 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
38 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 ...
0
votes
0answers
25 views

Encoding normalization of emails

I'm a reading a text file which contains lots of emails (in the mbox format). Each email has a charset defined in the header by the mail client. However, there is a ...
0
votes
0answers
30 views

Rails mixin to handle address fields

I'm currently working on a Rails 5.2 application where I'm trying to parse users data into a PDF form. The data from the user is received via a JSON object. The fields of the form are as follow: <...
2
votes
1answer
66 views

RuboCop: parameter list too long in initialize method

I have an initialize method for a class that looks like this: ...
3
votes
1answer
69 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
23 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
67 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
51 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
89 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
93 views

Ruby Hash to XML

I've just made this "serialization" module in Ruby that takes a hash and outputs a XML string. ...
5
votes
2answers
102 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
73 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
14 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
45 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
71 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
26 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
50 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
31 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
85 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
73 views

Model Association (Rails 5 API)

I have a Character model that has a CharClass and ClassPerks child. Currently I am ...
0
votes
0answers
37 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
47 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
50 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
100 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
152 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 ...
0
votes
1answer
79 views

Update the frequency of Sidekiq job

I'm working on a feature which user can set frequency of a job. I am using Sidekiq. My solution is when someone updates the frequency from view, I will delete all old scheduled jobs and create a new ...
5
votes
3answers
160 views

Hangman game in Ruby

I'm just a few months in learning to code and never had my code reviewed. Is this class structure ok? Should I split it differently? How is the code overall? ...
1
vote
1answer
172 views

Rails passing in params to association on create method

I am currently using a belongs_to relationship in my Rails application to link a map and a group an object that way I can assign those maps to the user based on the ...
4
votes
2answers
77 views

A method that shows maps users are a part of

A little background: My app has two models called mapgroups and usergroups. A map belongs ...
1
vote
1answer
128 views

RSpec test for handling known IP addresses

I want to replace the array of ips with a method (like known_ips or just ips) but I don't know how. I'll use this ...
2
votes
1answer
49 views

Command-line search for web-scraped TV Guide listings

This is a project that I am looking to clean up. The code is fully functioning and it has already been turned in, so I figured I can let Code Review help me. The git repository can be found here: ...
1
vote
2answers
42 views

Solution to 99 lisp problems, p09 in ruby [closed]

I am fairly new to ruby, and I am worried that my solution to problem 9 of the 99 lisp problems is extremly convoluted and inefficient. The problem is: My Code ...
6
votes
3answers
98 views

A method that calculates win streaks

Right now, I have the following: A win_streak column on the User table. This method in ...
2
votes
4answers
72 views

Cut each N symbol from array

What is the most efficient and productive way to cut each N symbol from a string? For instance, n = 5; str = '1234A1234B1234C'; result: "123412341234" This is my approach: ...
0
votes
0answers
267 views

Rails Strong Parameters Filtering

In my Rails controller with strong parameters, I have the typical my_model_params private function to filter out any "scary internet params". One of the parameters ...
5
votes
1answer
102 views

Program to count common words in documents

I finished my first program in Ruby and I would like to share it with you so I can get some suggestions or recommendations. I'd really like to hear them because I am learning and I want to have a ...