Stack Exchange Network

Stack Exchange network consists of 175 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.

1
vote
0answers
18 views

Re-creating user discounts nightly

I'm calling these two methods on a Worker that is executed every 24 hours at midnight in the background. The code seems to be a little bit difficult to read and I'm not sure if i'm iterating through ...
1
vote
1answer
30 views

Getting the count of how many times a route has been hit

I have this log file (example below) and I'm trying to find the number of times a particular route is called. Example log file: ...
10
votes
0answers
57 views

Ruby chess engine gem

This is my first Ruby gem that claims to provide all the rules of the chess game. My goal was to keep this library as simple as possible via OOP principles, and I'd be glad to hear any feedback from ...
0
votes
1answer
29 views

Modular multiplicative inverse in Ruby

I implemented an algorithm to find the modular multiplicative inverse of an integer. The code works, but it is too slow and I don't know why. I compared it with an algorithm I found in Rosetta Code, ...
1
vote
1answer
28 views

Ruby on Rails - Creating many models associated with another one

So I have the following models: ...
1
vote
0answers
23 views

Ruby exercise in writing and reading a file [closed]

I've been asked to improve the modular decomposition of the main by moving as many lines of code out of main as possible, but i have no idea how i should do this ...
3
votes
1answer
19 views

Ruby command to edit a field in a SAM file

Inspired by a bioinformatics question on Stack Overflow, I wanted to brush up on my Ruby knowledge, since I’ve been meaning to replace my command-line use of Perl by Ruby. Briefly, the problem ...
1
vote
1answer
31 views

Rspec test for Rails method to return alphabetically sorted list of tags

I have one model class as listed here: class Post < ActiveRecord::Base has_many :comments def tags comments.map(&:tag).uniq.sort end end and ...
3
votes
0answers
35 views

Adding an item to a hierarchical data structure

What I need to do is create a new object, modify it using a recursive function, then merge it with another object, and do this all in such a way that the values of the new object take precedence over ...
1
vote
0answers
28 views

Atbash cipher in Ruby

(Here's a REPL if you want to test it online: https://repl.it/repls/RecentMonstrousOffice) I tried to implement the Atbash cipher in Ruby and this is my final code: ...
2
votes
0answers
38 views

Validating Amazon CloudFormation templates using Rspec

I have created an open source project that uses Rspec to validate the formatting of AWS::CloudFormation::Init YAML blocks in CloudFormation templates.1 My project is here. Some general concerns: Is ...
3
votes
1answer
47 views

(Ruby version) Rotate linked list to the right by k places

I saw this question (javascript - rotate linked list to the right by k places) the other day and I tried implementing it in Ruby in a totally different way. Here's the code (I also created a REPL if ...
5
votes
2answers
62 views

Vigenère cipher in Ruby

What I'm trying to do: implement the Vigenère cipher in Ruby. I already have a working version, but I want to make sure it is efficient and well-designed. ...
2
votes
2answers
57 views

Keep ABC size down for conditional string concatenation in Ruby

This method takes a comment object and displays it correctly depending on what columns are available. EVENT_TEXT and REASON_TEXT ...
3
votes
1answer
104 views

Mars Rover challenge in Ruby

I have written a simplified version of the Mars Rover challenge in Ruby. Please review it for best coding practices. A rover’s position and location is represented by a combination of x and y co-...
0
votes
1answer
27 views

Searching for combinations of words and numbers

My model called Customer contains a method called generate_fields which creates records based on its return values. ...
4
votes
1answer
63 views

LinkedList Implementation

I have created a LinkedList in Ruby and was wondering if anyone had any input on efficiencies that I could add or deficiencies I could remove. ...
1
vote
0answers
50 views

Rails dynamically changing parts of view but using the same method in controller

I have this update method which decides whether to update or recreate(same as update but resets the approval_status and create_date) of the building_approval object. I have the on_progress? method on ...
2
votes
1answer
68 views

Ruby Beginner - Fuzzy matching / string manipulation

There is no intended end use for this. It is for learning and development only. I got carried away following an example and ended up with a miniaturised vehicle registration system. You can bulk ...
0
votes
0answers
34 views

ROR - Point of Sale (POS)

I've the following scenario: the user clicks the "Sales" button which redirects to the creation view of the Shopping Cart. Then, the user enters the EAN code and the Quantity, presses "Add" and the ...
3
votes
0answers
38 views

Ruby - Core skills example project (command line vehicle registry)

There are no requirements for this project nor will it ever be used for any purpose. I used this project to cement my knowledge of basic programming skills, I got bored copying the examples and felt ...
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
58 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
96 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
90 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
86 views

Arrays of hashes to hash

Task: convert this array of hashes: animals = [ {"cats" => 3}, {"dogs" => 5 } ] to this hash: ...
0
votes
0answers
35 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
40 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
41 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
165 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
155 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
49 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
44 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
44 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
37 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
105 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
61 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
61 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
106 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
52 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
41 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
37 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
87 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
51 views

Trie structure using Hash in Ruby

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