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

learn more… | top users | synonyms

8
votes
3answers
54 views

CodeWars mathematical expresion evaluator

I recently wrote the following code for a codewars.com kata for evaluating mathematical expressions. I've been writing ruby for years, but almost everything I do is for personal use and isn't ...
1
vote
1answer
38 views

Establishing parameters for a sales report, with default boolean and date values

The idea is that I am getting the params from a GET request in the form of a Hash (symbol→str) and I want to transform them into dates and booleans. For that ...
3
votes
6answers
499 views

Find the letter 'z' within three characters after an 'a'

It works, just feel that my solution is too complicated. ...
2
votes
0answers
37 views

Which version of custom mysql sql duplicate_key update query is cleaner?

The goal is to create an activity or update it's counter if it is already present. And to be super accurate the code avoids race conditions with a custom ...
1
vote
1answer
38 views

Rake task to send users a reminder to post with conditions

I am implementing a feature that reminds users to make a post via email if the user has set daily reminders to true he has not posted yet today and if the current hour matches when he would like ...
2
votes
1answer
44 views

“Can a list of meetings all be scheduled in a conference room?”

I was given this question at an interview for a position I just got rejected by, so looking to improve and see what better answers there are! ...
2
votes
1answer
37 views

Checkboxes array to delete images

Basically I'm displaying an array of images on a page with checkboxes. The idea is when a user is editing a post and the checkbox is checked, the image will get deleted. Each image also has an ...
3
votes
0answers
31 views

Fat Controller Action - Deep nested filters

I have this really really long controller action and would like someone to help me break it down. ...
2
votes
1answer
44 views

Truncating article text

I need to show article's content based on this logic: if article's content has to be truncated (e.g for preview) if there's [read more] substring in the content ...
4
votes
1answer
45 views

Simple Ruby program to model a prepaid transit card system

I have written a simple Ruby program to model a transit card system which aims to address the following user stories. I wanted to see whether I could get any feedback on it. My main interest is ...
3
votes
2answers
49 views

Show all records when current user is admin

I have the following. How best to refactor it: ...
-3
votes
0answers
31 views

API-only e-commerce Rails app

I'm building an API-only e-commerce Rails app with lots of controllers and an admin panel. I'm thinking on how to namespace/organize my routes and controllers. The best guess I had for now is to try ...
1
vote
1answer
40 views

Creating a dictionary

I have a Ruby programming task. My code passes all the rspec requirements, but I am not sure if I've done it in the right way. And I'm not quite sure why I need ...
1
vote
2answers
37 views

Creating a percentage complete method for a form

I am a relatively new Rails developer and doctor doing research. In my Rails based research projects I often have questionnaires for which I provide a "% complete" parameter. Here is an example. You ...
5
votes
2answers
55 views

Simple medication dosage calculator

I am a nurse and I'm learning to code. I have coded this simple tool that helps me doing some common nursing formulas for medication. It works, however I think it is too bulky/redundant. Can you help ...
3
votes
1answer
27 views

Classes for attributes validation

I have two classes responsible for attributes validation: ...
1
vote
0answers
21 views

Unlock spreadsheet files - follow up 2

Awhile ago I created a program that unlocked spreadsheets, for a better understanding of what happens when it's run, see here. I decided to rewrite it again, and go for a more OOP approach.. My ...
0
votes
1answer
48 views

Using as few queries as possible for many table associations

I have a table containing about 30k rows of data and there's several table associations. The problem is that there's like 18 columns, and each column requires 1 db query. Here's an example of what ...
-4
votes
1answer
34 views

Better way to code this Ruby class with similar functions [duplicate]

I have coded this Ruby code. Everything here works perfect as intended, however it is a real mess. What would be the best way to clean this up with best practices and such? ...
6
votes
0answers
122 views

Extracting single files from a tarball (spreadsheets)

I've created a program that will pull spreadsheets out of a large tarball. First it specifies the file name through the "folio" number which is given as an argument when the program is called. From ...
0
votes
2answers
36 views

Duplication of enum across two models

In my Rails app, I have two classes each with the same enum for status. Code climate is complaining about duplication. ...
3
votes
1answer
52 views

Turning an Integer into an array of ints

My goal here is pretty simple, I want to turn a number like 12435987234 into an array of integers in reverse order. So that would look like: ...
4
votes
2answers
59 views

Find all integers between m and n whose sum of squared divisors is itself a square

Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a square! Given two ...
2
votes
0answers
27 views

Formatting a long HTML document in a model method

I was asked to make a view which is a mix of HTML & ERB logic available in multiple views. At first this seemed pretty simple. However, some of these views required the output to be plaintext ...
3
votes
1answer
41 views

Ghostscript check, sends e-mail if one occurs

I've created a program that will search our work server where Ghostscripts occur. How it accomplishes this is by first sshing to the server specified, running a ...
4
votes
2answers
43 views

Patching Strings with Ed Scripts

I'm using Ed scripts to track changes in a web app I'm developing. Ed scripts are probably the easiest kind of patch file for a computer to parse: detailed explanation of Ed scripts. I quickly put ...
5
votes
0answers
52 views

Object-Oriented Chess Game in Ruby

I wrote a chess game in Ruby using object-oriented principles. One of the challenges was deciding which particular methods/actions belonged to a particular class, as there were some that felt as if ...
4
votes
2answers
248 views

Hackerrank challenge - Dictionaries and Maps

This is a solution for the Day 8 hackerrank.com challenge. The basic idea of the challenge is to create a mapping of names to phone numbers based on the the given input, and later look up the phone ...
12
votes
2answers
101 views

Minesweeper: how many mines are near?

Minesweeper in Ruby (from exercism.io): Write a program that adds the numbers to a minesweeper board. Minesweeper is a popular game where the user has to find the mines using numeric hints ...
5
votes
2answers
40 views

Refactoring if statement based on a hash key

I have to call Article.to_draft/to_archive/publish method depending on the presence of the ...
6
votes
2answers
130 views

Cancel those hung print jobs

I've created a program that will list all hung print jobs on a specified server, from there it will load them and strip the jobs down to their Job ID then cancel ...
2
votes
2answers
67 views

“Speed date” interview questions

I'm learning Ruby and I would like to know if I have used the good syntax. My script works, but can I simplify it and make it more elegant. ...
4
votes
1answer
43 views

Rosalind problem “Consensus and Profile”

Source: Rosalind("Consensus and Profile") Brief summary ...
3
votes
1answer
51 views

Logging the load balance

I created a load balancing server at work and have to keep track of which server it adds the user to, so I wrote a little Ruby script that will do just that. I'm looking for any critique of my work, ...
15
votes
2answers
306 views

Count the occurence of nucleobases in DNA string

Inspired by this meta question I decided to take a look at Rosalind. Their first challenge seemed easy enough: An example of a length 21 DNA string (whose alphabet contains the symbols 'A', 'C', ...
4
votes
2answers
117 views

Balancing the server load

I've created a program that will take, a bunch of numbers from a range of 1 - 255, and then put them into 3 different strings(servers) equally. It does this by ...
5
votes
0answers
49 views

Error Handling for XML parser

I have the following Ruby code, which parses an XML document sax style (it's a very simplified version): ...
9
votes
3answers
92 views

Finding if sequential numbers for total exists

Question: Given a sequence of positive integers A and an integer T, return whether there is a continuous sequence of A that sums up to exactly T Example: ...
-5
votes
1answer
71 views

Python to Ruby: inconsistency with float ceil() [closed]

Just for fun, I am trying to convert the following Python from math import * print map(lambda count: ceil( 6 * cos((count + i) * pi / 5) ), range(100)) Which ...
13
votes
1answer
53 views

TicTacToe with AI in ruby - follow-up overload

I already posted this program numerous times, always surprised by the amount of improvement that is possible suggested by people here. Is it possible to make it even better, without nitpicking? At ...
6
votes
1answer
58 views

Script to redo a rails migration easily

I need to redo a migration occasionally. The workflow is usually something like this: find or ls | grep the migration using ...
3
votes
0answers
33 views

Simplify the way a user retrieves scraped information

I'm allowing a user to scrape information from LinkedIn by entering the profile url. However I'm relatively new to creating a service (is that even the correct use case?) and I feel like there's room ...
6
votes
1answer
72 views

Simple authorization module with Rails

I created a simple Authorization module with Rails. I found that there are other authorization systems, such as CanCanCan, but they grant permissions at Model level and, for this particular website I ...
5
votes
2answers
65 views

Selecting users with biopsies in a given country for charting

I have this monstrosity ...
16
votes
1answer
271 views

Are your servers down…?

If you came here because of the title, chances are your server isn't down. But if by some miraculous reason it is: A while ago, I posted a program that would ssh and ping all the servers at work. I ...
1
vote
1answer
66 views

Simplifying Rails Validation [closed]

I have four fields a, b, c, and d. All of them must be populated if any of them have a value. So what I want to do is validate that they are all populated, if any of them have a value. I'm trying ...
6
votes
2answers
73 views

Data-structure exploration

On my quest to learn Ruby I figured exploring the proper usage of different data-structures would be invaluable, including strings, arrays and hashes. I decided to build a hash containing the numbers ...
6
votes
2answers
82 views

Server status checker

I've created a program for work that checks the status of all our servers quickly. What we use to have to do is ssh into each server manually. I'm looking for some ...
2
votes
2answers
65 views

Rating the quality of a response based on the number of typos

I have this method which returns the number, but Rubocop said: Assignment Branch Condition size for rating is too high. [15.84/15] ...
4
votes
2answers
30 views

Extracting components of a filename

I have a string str ="/Users/user/Desktop/task/U6342_Account_20150112.txt" I need return only U6342_Account_20150112 as an ...