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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

1
vote
0answers
14 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
13 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
19 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
21 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: <...
1
vote
1answer
39 views

RuboCop: parameter list too long in initialize method

I have an initialize method for a class that looks like this: ...
3
votes
1answer
52 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
21 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
55 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
35 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. ...
2
votes
0answers
77 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
35 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
65 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: ...
1
vote
2answers
59 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
27 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
39 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
39 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
50 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
48 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
29 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
77 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
64 views

Model Association (Rails 5 API)

I have a Character model that has a CharClass and ClassPerks child. Currently I am ...
0
votes
0answers
33 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
44 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
47 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
147 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
66 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
118 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
81 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
76 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
89 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
48 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
38 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
93 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
221 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
89 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 ...
3
votes
1answer
66 views

Failed job application test: program which alters 2d list based on commands

I recently was given this question for an interview application and am wondering where I went wrong. (The whole answer is contained in a skeleton which they gave me which I haven't included here so it'...
1
vote
0answers
51 views

Ruby Sudoku Solver without classes

I'm writing a Sudoku solver in Ruby to complete a coding challenge with the following restrictions. Failing to follow the following restrictions will result in an invalid submission: Do ...
0
votes
1answer
49 views

Buying in cash or coins

Does anyone have any ideas on how I can refactor these methods to get rid of the duplication? The first, third and fourth lines of both methods do the same thing. I'm having trouble for some reason ...
1
vote
1answer
97 views

Dice roller in Ruby (mainly for D&D)

I have been working with Ruby for about a week or two now, and I wanted to create a dice-rolling application that intakes any string (e.g. 1d4 + 1 or 3d20 + 4) and outputs the correct dice rolling. <...
2
votes
1answer
79 views

Ruby Connected Components in a Graph

I've written the following code to find the connected components of a graph in ruby, but it is quite slow since I don't use any sensible data structure for the disjoint sets, and hence find_set is ...
0
votes
2answers
116 views

Remove duplication in Ruby map with conditional entries

I have a nasty (IMO) piece of code for a datatable configuration, how do i best remove the duplication here? I've tried the obvious things I know (collapsing into one statement and trying inline ...
0
votes
1answer
60 views

Ruby BST code for insertion implementation

After some help in understanding difference why direct assignment with setter methods don't work, here is my code for a simple BST in ruby. Would appreciate your reviews and suggestions to refactor ...
2
votes
1answer
338 views

Bank ATM machine in Ruby

I've made a simple implementation of a bank ATM machine in pure Ruby. I'd like to hear some recommendations to make my code more idiomatic. atm.rb This is the startup file. I didn't use a class and ...
1
vote
1answer
67 views

Langton's Ant cellular automaton in Ruby

I wrote a Langton's Ant cellular automaton simulator in Ruby using object oriented principles. This code works. It requires the drawille library. I would like to ...
4
votes
1answer
80 views

Recursive Ruby merge sort

I have implemented a merge sort in Ruby. (Yes, I know, there's Array#sort) I would like to get feedback on code quality and optimization. ...