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

learn more… | top users | synonyms

0
votes
0answers
12 views

How to optimize the processing speed of HUGE arrays in Ruby

I have created a program which takes a value x and uses this value to create a power of ten value like so 10 ** x. This has ...
3
votes
1answer
13 views

Simpler method to find users in child categories

I am using the ancestry gem to organize my post categories tree. I have 8 parent categories, and they all have many child categories. To retrieve an array of child categories, I use: ...
1
vote
0answers
17 views

Generating a Postgres query dealing with creating a time series

I want to sum the number of my published publications model in a given interval and return a time series. (related SO) The main challenge is that I want the code to respect the time zone passed to ...
0
votes
0answers
9 views
3
votes
0answers
27 views

Seeding a database

I'm seeding my database with really complex code as I think. It works but is not good. Constrains: Every meal has exactly ONE main dish (marked as is_main in ...
-5
votes
0answers
24 views

Solve Caesar Cipher using Ruby [on hold]

I am new to the Ruby community and would like to advice/help. I have been stuck for so long on this question I need some serious help. I have to write a function to solve a Caesar Cipher. I must do ...
0
votes
0answers
17 views

Whois lookup tool

I've created a tool that searches for keywords given as ARGV then scrapes the first page of Google for the keywords, from there it logs all the urls found on ...
1
vote
1answer
44 views

Removing folders from my rails app with rake

I'm trying to remove the tmp/letter_opener folder. Everything works fine, just wondering if there's a better way to write it. My next step is to write some tests, ...
-4
votes
0answers
38 views

Loading a huge number of images in the View [closed]

I have to just load huge number(1 million) of images in a view. My app is fetching the images from api call using background jobs but my app is getting very slower when I load the view it is taking ...
1
vote
0answers
20 views

Use Ruby variable in Style tag

In my view, I have a CSS class in ruby variable which I'm using in style tag like below: ...
6
votes
2answers
77 views

Prime multiplication table

I am new to Ruby (1 year as hobby project on weekends) and solved a code challenge and it was not as good as they wanted. I want to know how i could make it better and how to make the structure ...
1
vote
0answers
35 views

Progressively split and map a large, line-based string

Goal I have a large string (~10MB in ~400k lines). I want to "efficiently" split it on a delimiter and map the resulting sets of lines. Efficiently is defined as something that is fast (wall time), ...
2
votes
0answers
35 views

A two-method program for running background jobs

Edit: since originally posting this I have: realized that it won't run from irb/pry, and refactored to remove some sleep calls. I wanted to make a program for ...
0
votes
1answer
21 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
52 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
127 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
41 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
28 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
32 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
119 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
46 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
40 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
59 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
34 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
48 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
24 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
117 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
54 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
24 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
44 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
42 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
34 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
74 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
50 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
51 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
1answer
43 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
48 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
56 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
51 views

Show all records when current user is admin

I have the following. How best to refactor it: ...
1
vote
1answer
48 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
40 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
59 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 ...