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
votes
0answers
10 views

Difference between functions written via Ruby and PHP

I have a little function written in Ruby: ...
-1
votes
0answers
12 views

Placing long return hardcoded objects of a method

I have a static Hash object that can either be a constant or return of a method in a class. For example: ...
4
votes
2answers
38 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
203 views

Is there a way in Ruby to make just any one out of many keyword arguments required? [closed]

I am trying to write a method, that works with three types of arguments, but requires only one of them. def convert(arg_a: 1, arg_b: 2, arg_c: 'foo') end Please ...
2
votes
1answer
44 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
72 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
24 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
58 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
43 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
33 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
36 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
57 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
93 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
82 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
82 views

Arrays of hashes to hash

Task: convert this array of hashes: animals = [ {"cats" => 3}, {"dogs" => 5 } ] to this hash: ...
0
votes
0answers
30 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
0answers
58 views

XLSX to CSV script with column re-ordering

I am still learning Ruby and object oriented programming. I wrote an Excel Export CSV Parser script, which does the following: reads an XLSX file creates a temp file re-orders columns generates a ...
0
votes
1answer
39 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
40 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
122 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
138 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
41 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
42 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
36 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
45 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
49 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
53 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
50 views

Partition array to hash in ruby

Problem: convert this array of hashes: ...
2
votes
1answer
31 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
90 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
48 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
39 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
33 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
82 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
41 views

Trie structure using Hash in Ruby

This is a follow-up to Boggle board solver in Ruby ...
4
votes
2answers
102 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
68 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
66 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
119 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
277 views

RuboCop: parameter list too long in initialize method

I have an initialize method for a class that looks like this: ...
3
votes
1answer
86 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
34 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
81 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
61 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. ...