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
1
vote
1answer
32 views

Case of Cyclomatic Complexity

I'm trying to recreate the method inject (Works like Reduce) from ruby Enumerable Module. Using Rubocop (A Linter) I got the error: ...
1
vote
1answer
34 views

custom hash from group_by hash

I am trying to create a custom hash from a table. User has many transactions. A transaction has a ...
1
vote
1answer
30 views

Ruby parallel assignment

I recently wrote the following code: ...
1
vote
0answers
30 views

Return values from array A in the order they are in array B

So my question is the cleanest way to do #product_panels_for below: ...
1
vote
0answers
33 views

Advent of Code Day 3, how to optimize my ruby solution?

I have solved the 3rd day puzzle of Advent of Code but wanted some feedback on my solution. The puzzle here wants to find where two jumbled wires intersect closest to the origin. Puzzle input is ...
2
votes
1answer
22 views

Comparing verbosity of algorithmic Ruby class

At a high level, I'm writing a Ruby class that compares components on two differing versions of the same JSON structure, which in turn decides whether or not said elements should be updated on a PDF ...
7
votes
1answer
70 views

Incremental, encrypted backups for git

I would appreciate any review of the following script I recently posted on GitHub (gitcrypto). Most notably, I would be interested in a review of the cryptographic aspects (I am not an expert in this ...
2
votes
1answer
86 views

Remove multiple array elements by indices

I prepared a method to make possible to select elements of the array except for some indexes. ...
2
votes
1answer
70 views

Tentative to transform this scrape script into a class object program

From the last few days I have been studying scrapping webpages and for further development I challenge myself to transform the script I have created into a class which will receive inputs from a user. ...
2
votes
0answers
34 views

Ruby coin toss probability tool

I haven't been programming for a while, I wanted to do a simple project to warm myself up and get back into the game; I made this simple tool that finds the probabilities of coin toss combinations. ...
1
vote
1answer
1k views

Let's play Rock, Paper, Scissors with Ruby

I'm just looking for any tips to improve the code, particularly easier ways to change the main logic of the code so that it's shorter. ...
2
votes
0answers
63 views

Ruby script for automating software install on a brand new Linux OS

I have some scripts to automate software install, apply some configurations and so on after installing a new system. I used to have them as bash scripts but it was generally a poor idea. I have ...
2
votes
0answers
42 views

Change architecture of Ruby app to be more object oriented, readable

I'm working on a Slack bot for service desk which sends direct message to user on a Slack when their ticket will be on user_action_needed status. I'm using AWS ...
2
votes
2answers
3k views

Ruby Anagrams Checker

I am quite new to Ruby, coming from a JavaScript background. I wrote this simple Ruby script that finds whether two strings are anagrams or not. To run it: ruby ruby_anagrams.rb 'script1' 'script2' ...
1
vote
1answer
57 views

Rails: create a relationship between comment and user

I'm trying to connect the create of a comment to the current_user. I have a model comment which is a polymorphic association. <...
1
vote
1answer
29 views

Concatenate unless note [closed]

mails = [] mails.concat(@note.cc_emails) unless @note.cc_emails.nil? mails.concat(@note.to_emails) unless @note.to_emails.nil? Everything what I'm doing here is ...
1
vote
1answer
52 views

Ruby: Remove middle node from Linked List

Currently, I'm going over the CTCI, I'm working on the problem removing the middle node. I'm using Ruby to go over these problems. I have the following solution. ...
2
votes
2answers
99 views

Rock, Paper, Scissors completed game

I have just completed my first Ruby OOP project. Fairly simple but still a bit time consuming as I am still learning the language. I would like feedback and ways I can improve on this and make the ...
1
vote
1answer
51 views

Rails controller method to show an optionally scaled image using MiniMagick

I've got below implementation for my controller and show action which implements MiniMagick gem. I've just wondering is there any better way to write it down? If ...
3
votes
1answer
62 views

Ensure multiple steps work/saving multiple models via a service

I just thought of something new re: saving multiple objects in Rails (though Rails is not necessary). Objectives: Create an author and a tomato, but both of those must be valid. If invalid creation, ...
2
votes
1answer
209 views

Listing employees, categorized by license expiration date

I am working on a personal project and I have hit a wall. I know I am writing bad code and I really want to refactor the code below. The application has three tables on the same page. Each table ...
4
votes
2answers
63 views

Rails Helper to display rating in stars

Using Rails 6. Here's a piece that I wrote just to display number of stars. Obviously I am disgusted by my own code. How would you refactor? ...
2
votes
1answer
1k 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 ...
3
votes
0answers
43 views

Assigning raffle numbers to users in Rails

Background One part of our Rails app is running a Raffle, usually twice a month, with around 600k entrants each round. Each raffle ticket record will have at least a unique raffle number (consisting ...
5
votes
1answer
270 views

Querying multiple related records in Rails

I have an Account, User and Group model. All User and <...
8
votes
1answer
1k views

Parameter list too long in initialize method

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

RSpec shared example for CRUD Controllers that might be nested or not

I've been trying to create a shared example to quickly and efficiently test controllers with CRUD operations that might also be nested. I came up with this ...
2
votes
1answer
100 views

Rails 5 helpers to fetch tasks with different filters

I moved a lot of the loading/logic from my view to my controller, and it's working great but after I did this I now have several very similar helper methods in my controller. What is a more efficient ...
3
votes
1answer
122 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). ...
5
votes
2answers
3k views

Rails validating API parameters

I wanted to keep my API request logic separate form the controller logic. I therefore make use of a separate model (EmailChecker) that creates an instance of this ...
1
vote
2answers
60 views

Removing duplicate hashes in an array while keeping count of the times the hash was present

I have an array of hashes (price_params['items']) where each item has a key called quantity what I'm trying to do is to clean ...
2
votes
1answer
350 views

Redis lock implementation

Considering I'm not implementing distributed lock mechanism, is this code correct and clear? ...
5
votes
1answer
1k views

Rails & RSpec - Testing API with request specs and shared examples

I have written the following shared examples which are used in multiple request specs to test a namespaced RESTful JSON API. Application details: Rails 4.2, RSpec 3.5, Devise for authentication and ...
7
votes
4answers
2k views

Towers of Hanoi

I am just learning how to code in Ruby now with no prior experience. This is 3 towers of Hanoi where the user selects where to choose from and where to go with each disc, and not to have a bigger disc ...
4
votes
2answers
381 views

Tower of Hanoi solver in Ruby

Solved the classic Tower of Hanoi problem in Ruby, using recursion. Would love your feedback on this. ...
-1
votes
1answer
31 views

Translator method failing to translate two words [closed]

Sorry if this has been answered to death—I'm working on a pig latin translator for Odin Project. The code below works fine for individual words, but when it receives two words ("eat pie"), the output ...
4
votes
1answer
67 views

Repeater for blocks of Ruby

I've written a module for repeating blocks of code, generally to cover issues related to eventual consistency and testing screen elements which may take some time to fully load. It looks like this: <...
1
vote
1answer
35 views

Enumerating AWS instances in Rails, with error handling

I have created a method, which is raising the same exception in case of any error: ...
0
votes
1answer
27 views

ActiveRecord Query for many to many association

I have two Models in my Rails 6 / PostgreSQL application which have a many to many relation; Car and Driver. The goal is to get ...
2
votes
1answer
43 views

Command-line implementation of Mastermind

I just finished this command-line implementation of the Mastermind board game that allows two players to play against each other. I'm fairly new to Ruby, but I think I did a decent job with this. ...
2
votes
1answer
98 views

Ruby code to parse and analyze social media stats in json format

What do you think about this code I wrote. It reads several json files ( I attached them as pastebins) and the code outputs summary information calculated from the input. ...
3
votes
1answer
51 views

Store personal data for later use

I'm new with Ruby and am trying to improve my coding skills. This program gets personal information for three people, and then prints them. It works, but I'm sure it's not the best and certainly not ...
2
votes
1answer
181 views

Easily interacting with two external apis

Recently I rewrote some methods/functions written by a previous developer mostly due to the fact that the previous implementation overdid the whole 'OO' thing, and used inheritance inappropriately. ...
7
votes
2answers
1k views

Counting the elements of one array that are less than or equal to some other numbers

I have a method which compares two array О(n2), maxes with each element in nums against <...
0
votes
1answer
364 views

Add values to multiple keys in one line

I Have orders table, every order has different payment method and made by different user, has different total of money. and i want to make a detailed report, i export date as a hash to the views, as ...
1
vote
1answer
117 views

better multiple fields validation on ruby/rails

I have a form for an item (Job Item), that has sets of 2 fields based on a type. field and field + _dolar e.g: ...
3
votes
0answers
120 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 ...
3
votes
2answers
75 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
62 views

Calculate the percentage of sum of hash values

Please review my code and help on How can I make it better calculation in method and class definition with SOLID ruby principles?? The application has a static JSON file which contains: ...
2
votes
1answer
78 views

Remove duplicates from an unsorted Linked List in Ruby

Currently I'm going over the cracking the coding interview. I'm in the Linked List 2.1 question which is as follow: Remove Duplicates, write code to remove duplicates from an unsorted Linked List....

1
2 3 4 5
32