We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [ruby]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
22 views

Short analogue of Riffle[] accepting two blocks

I have an array of some elements that I need to loop through (i.e. execute some block A on each element) but between them I have also to "clean up" (block ...
2
votes
1answer
61 views

Sorting an assortment of strings and integers together, while keeping them separate

I put a solution to this coding problem together. The problem is this: Create a function that takes an array, finds the most often repeated element(s) within it and returns it/them in an array. The ...
2
votes
0answers
100 views

Esoteric programming language in Ruby

I have recently created an esoteric programming language called 01 and I will be grateful for a code review and any opinions or suggestions about the future of this language. GitHub ...
4
votes
1answer
100 views

Download a Git repo without .git folder

Coming from Python, JavaScript and PHP, I'd like to learn to write Ruby in the way it's "supposed to". Well-written Python code is called "Pythonic", so I'd like to know how idiomatic my Ruby code is. ...
0
votes
1answer
154 views

Arrays of hashes to hash

Task: convert this array of hashes: animals = [ {"cats" => 3}, {"dogs" => 5 } ] to this hash: ...
0
votes
0answers
38 views

Class to create and send a PDF form with attached documents

I'm currently working on building a class to create a PDF form application with attached documents and sending that file to an endpoint in Box Api. I have found extremely difficult managing ...
0
votes
1answer
30 views

Updating one model field based on the associated model's field

I'm wondering if there is any way we can optimize the following code. Scenario is Library's active field should be ...
0
votes
1answer
41 views

Gomoku Game in Ruby

I learnt lots about ruby from my last post Game of Life in Ruby, so I have my next try in Ruby, it is Gomoku. It is still an console game and I use three classes ...
5
votes
1answer
42 views

Scheduled file sorting with Ruby

I have a script running as an hourly cron job. It finds all screenshots on the Desktop and moves them to directories sorted by year/month/day. On MacOS, screenshots are automatically saved to the ...
1
vote
1answer
330 views

Ruby on Rails quiz function

I have created a quiz function in my rails application. Since I want to track responses and make it a server-side application I created a table to record the responses of the questions people answer. ...
5
votes
1answer
227 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 ...
2
votes
1answer
50 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
49 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. ...
1
vote
0answers
47 views

TDD for Ruby On Rails API for group event items

I found myself working in this coding exercise for a work offer. I tried to apply TDD in the process but I didn't get any feedback from the company and I really would like to know what can be improved ...
1
vote
0answers
43 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
49 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
285 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: ...
1
vote
2answers
77 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
76 views

Partition array to hash in ruby

Problem: convert this array of hashes: ...
2
votes
1answer
32 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
231 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
73 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
66 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
42 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
45 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
101 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). ...
1
vote
1answer
65 views

Trie structure using Hash in Ruby

This is a follow-up to Boggle board solver in Ruby ...
4
votes
2answers
149 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 ...
3
votes
0answers
110 views

Script to auto-generate Markdown tables of contents

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
77 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
40 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
208 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 ...
3
votes
1answer
786 views

RuboCop: parameter list too long in initialize method

I have an initialize method for a class that looks like this: ...
3
votes
1answer
103 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 ...
1
vote
1answer
42 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
82 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
67 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
101 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 ...
2
votes
0answers
233 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
367 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: ...
3
votes
2answers
136 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 ...
2
votes
2answers
52 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
49 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
493 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
29 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'...
3
votes
1answer
293 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. ...
4
votes
1answer
137 views

Model Association (Rails 5 API)

I have a Character model that has a CharClass and ClassPerks child. Currently I am ...
3
votes
1answer
56 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
106 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 ...