Ruby is a multi-platform, open-source, dynamic, object-oriented, interpreted language created by Yukihiro Matsumoto (Matz) in 1993.
0
votes
0answers
11 views
Keep classes anonymous in TicTacToe program
My console TicTacToe program
This is my first large project attempt and I want to learn how to keep classes as anonymous as reasonable and as protected/secure as reasonable.
The program works as ...
3
votes
3answers
38 views
generate word list based on Spanish text file
I'm a beginner and wrote a program takes a text file and writes a downcased vocabulary list to another text file. I intend to use it mainly to work with text in Spanish, so I added a line to downcase ...
4
votes
2answers
113 views
Ruby method that returns an age from a date of birth
I have a method on my user model to calculate the user's age and return a human readable string. My user's can be between 1 month old and above so the returned string is different depending on if the ...
3
votes
0answers
31 views
Displaying a Google map with multiple complex markers and unique info windows
This JavaScript file is part of a large Ruby on Rails app. Any feedback is appreciated.
Update 3.7.16: as per @Jonah's suggestion, here's a description of the code's purpose:
I've built a ...
0
votes
1answer
23 views
NestedHash Class
I want to make a Ruby nested hash table class to avoid repeating ugly code and to keep my programs as true to the OOP paradigm as I can. Are there any ways to make this class definition smaller ...
2
votes
2answers
29 views
Choose a color with probability proportionate to its weight in a group of colors
Input: An array of colors with weights. e.g [['red', 10], ['blue', 20], ['green', 30]]
Output: A random color from the array, based on it's proportion to the other ...
2
votes
3answers
111 views
Adding minutes to a time value in Ruby
I recently submitted a code-challenge for an interview according to the following guidelines:
About
Write a function or method that accepts two mandatory arguments and returns a result.
...
1
vote
1answer
43 views
Select the element out of the array if its index is a Fibonacci number [closed]
I've some questions for an exam and wondered if somebody could take a look at my Fibonacci sequence that is supposed to answer this question:
"select the element out of the array if its index is a ...
1
vote
1answer
43 views
Updating an auto-generated invoice (future) when current plan changes
I've built-out a mechanism to go and find an auto-generated invoice and update it with new information when a plan is changed or if users are added to the plan for the current billing period. It will ...
1
vote
0answers
32 views
Given an input list of words and a string, output every different set of words that can make up that string
Problem:
Given an input list of words and a string, output every different set of words that you can find in the string from the given words. For example, input: word_list = ['dog', 'cats', ...
3
votes
1answer
54 views
Simple Caesar cipher cryptanalysis in Ruby
I really like Ruby and want to get better at it. Any input is appreciated.
Description
This program prompts the user for a string which is ciphertext resulting from a Caesar cipher given (English) ...
3
votes
1answer
32 views
Determining if a file or URL is a git repo or archive
I'm getting these three offenses:
libraries/helpers.rb:4:1: C: Method has too many lines. [11/10]
def get_files(url, file, destination)
^^^
...
2
votes
2answers
44 views
Find a palindrome using Ruby
I am preparing for an upcoming exam and have the following practice question..
Write a method to determine if a word is a palindrome, without using
the reverse method.
Most of you probably ...
1
vote
0answers
41 views
Multicolumn iterations with cucumber data tables in Ruby
Cucumber is not designed to support multi-column iterations, but it is possible to make it work. Here, I want to try each combination of path and role.
This is the Cucumber Gherkin:
...
1
vote
0answers
22 views
Generating sample data for a Rails application
I am working on generating sample data for my Rails application. For now we will just be using the sample data while we are designing the website. I'd like it to be as easy as possible to generate ...
1
vote
1answer
28 views
Order list of movies and save sorting in cookies
I did this project and I'm going back over it and trying to optimize some stuff. This is the movies_controller.rb file, which is basically a table that I need to sort based on user parameters. What I ...
3
votes
3answers
112 views
Deeply extract all used symbols from a hash of nested symbols in an array
I have a nested hash of symbols like this:
{
a: {
b: :c,
d: {
e: :f
}
},
g: :h
}
I want to build an array that contains all symbols used ...
2
votes
2answers
53 views
Checking days from now
I'm trying to respect the Ruby principle of keeping my code dry; however, in my conditional, I have different constants set to different days. But that's the only thing different. They're pretty much ...
2
votes
1answer
23 views
Testing a socket-based application
Summary: How can I best write tests that override socket-based communication for a library, capturing what is sent over the socket, and simulating responses based on what is sent?
Details
I'm adding ...
1
vote
1answer
43 views
Ruby backup/restore for provisioning
This is my second Ruby coding attempt. Also - this is my first OOP usage in Ruby.
I'm using if __FILE__ == $0 form here - same as it is in Python because it's ...
4
votes
0answers
40 views
Web scraping with Nokogiri
At work we have a need to know what printers are getting dangerously low on their toner, and paper consumption, etc..
So I've created a program that pulls the printer information off the websites the ...
1
vote
1answer
29 views
Destroy script for provisioning
Script intended to remove Vault & Consul setup before run re-provision them on server.
This is my first Ruby script, so will be perfect to see my mistakes here.
...
3
votes
1answer
33 views
Auto move files to a sub folder with Ruby
I started writing a script to handle my file downloads in osx because they quickly pile up and it gets time consuming to do this manually by drag and drop. I am looking forward to get some feedback.
...
8
votes
3answers
72 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
46 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
517 views
Find the letter 'z' within three characters after an 'a'
It works, just feel that my solution is too complicated.
...
3
votes
0answers
98 views
Custom MySQL duplicate_key update queries
The goal is to create an activity or update its counter if it's already present. And to be super accurate, the code avoids race conditions with a custom ...
1
vote
1answer
45 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
49 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
40 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
40 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
47 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
54 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
50 views
1
vote
1answer
45 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
58 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
28 views
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
51 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
40 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
129 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
40 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
64 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
29 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
44 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
55 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
259 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 ...