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

learn more… | top users | synonyms

1
vote
1answer
36 views

Conversational bot architecture

I am currently building a small conversational bot, and I am struggling with the architecture. I use Facebook Messenger combined with Wit.ai's API and a Shopify store API. My rails app is the ...
3
votes
2answers
46 views

Find existing session

I have this method in my rails app: ...
0
votes
0answers
5 views

Best way to build a JSON API coupled with HTML views in a Rails project [migrated]

I've got a Rails eCommerce project communicating with an iOS app. The iOS app receives JSON data from the Rails back-end, but there's also HTML rendering when a user comes to the project from his ...
2
votes
1answer
58 views

SE-like voting system

I've created a voting system that's similar to Stack Exchange's in a Ruby on Rails web app. It's working great - as far as I can tell, all the edge cases are caught. This is the action to cast a vote. ...
3
votes
3answers
126 views

Check if a store is currently open

This is the dirty bastard of my current code block, and I'm trying to find a way to improve this code for increased readability, but also functionality. The method checks if the store is currently ...
-1
votes
0answers
16 views

Can anyone explain me the Ruby Script answer for 'The Grid Search' Problem of HackerRank? [closed]

It's in the editorial. I'll paste the script below for reference. ...
3
votes
1answer
36 views

Mendelian inheritance

I started out with the Rosalind problems a while back. Turns out it's a great way to learn a new language. I'm still trying to learn Ruby, and while I haven't managed to use regular expressions as ...
0
votes
1answer
33 views

Change non-diagonal surrounding elements in a 2-D array

I'm a beginner working through an exercise on ruby arrays. Given a two-dimensional array with 0's and/or 1's, it should return an array with the non-diagonal surrounding elements of 1 changed to 1 if ...
0
votes
0answers
21 views

Renaming image files based on OCR words

I wanted to rename a large batch of image files, based on a best-guess attempt to OCR words from the file. These are all logos, which generally bear a the name of an organization. The code presumes ...
4
votes
3answers
82 views

Idiomatic ruby to calculate distance to points on a graph

Can this code be made more like idiomatic ruby using methods such as map or inject? @random_tour is a variable length array of points on a graph: ...
2
votes
1answer
54 views

Arabic numbers to Roman numerals conversion

The following converts Arabic numbers to Roman numerals. I decided to factor each digit into its place value, then use a mapping to convert it to its Roman equivalent. For example, 1997 is factored ...
0
votes
1answer
40 views

Common ancestor in a binary tree

This method finds the common ancestor of two nodes in a binary tree. Any style suggestions or ways to make it more idiomatic? Is the algorithm correct? Rubocop says the cyclomatic complexity is too ...
2
votes
1answer
49 views

Update record with CSV

I'm using Rails 4.2.5, and I'd like to update existing records with a csv file with two fields: id,category. Where if the category field is blank, it defaults to misc. Here's an example csv file: ...
4
votes
0answers
31 views

Using dynamic method names in place of case statements

Using Rubocop, pretty much any case statement is caught by the Cyclomatic Complexity cop, often the Assignment Branch Condition and method length cops as well. To get around this, I've been ...
4
votes
2answers
87 views

Optimize the CSV Upload function in Ruby On Rails

The code is working fine however, I would like to fix code after unless and can I store thread ID in the database too? Is there a way to improve performance? ...
0
votes
2answers
44 views

Extracting data from a string

I created a method that takes a string value with a fixed length of 9 characters and extracts three values, house (4 characters), ...
3
votes
0answers
77 views

Google CodeJam 2016 - Ruby - Counting Sheep

https://code.google.com/codejam/contest/6254486/dashboard#s=p0&a=0 I just wrote a small Ruby class to solve the first of the challenges in the G CodeJam. I am not strong at this sort thing so ...
3
votes
3answers
81 views

Finding the number in a list that differs in parity

Given any string with a series of numbers find out which one of the numbers differs from the others in evenness and return its position. Examples: ...
4
votes
1answer
62 views

Balanced parenthesis in Ruby

I'm solving the "Balanced Parenthesis" problem in Ruby, and I came up with this solution. ...
2
votes
0answers
19 views

ActiveAdmin menu-generating mixin

I've written an ActiveAdmin mixin, such that you can include it and call simple_menu_for Foo, to reduce duplicate code when working with simple models. Here is the ...
2
votes
2answers
114 views

Algorithm to rotate array elements in Ruby

I wrote this algorithm to rotate elements in an array. It's not very efficient, but it works. It has another disadvantage that it doesn't rotate right (it would be nice to pass it negative steps, for ...
2
votes
1answer
28 views

Order processing

I have recently built a plain old Ruby program using TDD with RSpec to model this. I wanted to get feedback. Repo For the company whose application we’re looking at, order processing looks ...
-1
votes
1answer
29 views

Skipping Google search results that point to certain sites

I have the following code that will skip certain URLs if needed: ...
1
vote
0answers
21 views

Custom bang! method and Rails validation

I have a model called booking. ...
0
votes
0answers
40 views

Whitewidow, SQL vulnerability web scraper

I believe it was yesterday I posted a program that scrapes google for SQL vulnerable web pages here. I never got an answer, so I just went all out and made it look a little prettier, it still only ...
3
votes
0answers
45 views

SQL vulnerability web scraper

I've created a program that will be used for pentesting. It scrapes the first page of Google out of an array of searches. It then attempts to find an SQL error within the site by adding an apostrophe ...
1
vote
1answer
59 views

Refactor code to solve the 'Line is too long' error in rubocop [closed]

Method.create(domain_id: domain.id, type_notification: type, message: title, url: url, owner_id: self.user.id) How can I reduce this line to 80 ?
4
votes
2answers
68 views

Product of 2 numbers equals sum of numbers between them

Problem: Find all the pairs (a, b) whose product is equal to the sum of all numbers in the sequence [1..n] excluding both a and b. I have made code for one program and need refactoring for code to ...
1
vote
3answers
60 views

Project Euler - Smallest multiple (Ruby)

My code is very slow to run, and I am trying to find a way to make it more efficient. I know there must be a better way than to write each modulo operation. The goal of the script is to find the ...
1
vote
1answer
22 views

Mini Test testing save on one and many trips

I know there is a balance to be struck between writing dry code and damp code but I have the feeling that this is a bit too repeative. Is there a terse yet self explainatory way to rewrite these ...
3
votes
2answers
42 views

Ruby method that is validating the payload received

What is a cleaner and/or clearer way of writing the following method ...
2
votes
1answer
40 views

Count associations in a Ruby model

I'm trying to figure out if there's a better way to run the code below. Basically Course is an association of Student and ...
2
votes
0answers
35 views

Dynamically create instance variables from a list of classes

I have a situation, where I want to add many classes as instance variables of another class, plus perform some action on each class. The purpose is to have an 'app' with many 'views', to represent ...
0
votes
2answers
50 views

Notify owner of post and other commenters

I have a rails4 app. When a user comments on a post it should send a notification to all the guys who commented on the post and to the post creator. I have a working method in the controller, but it's ...
1
vote
2answers
79 views

Controller method to manage SMS subscriptions

I have a huge method in my controller that is not DRY and just could use some general TLC. I'm new to ruby and I have not refactored my own code before, only contrived code you find on tutorials. ...
2
votes
1answer
34 views

Changing a user status flag, with validation

I am writing a function which on update of any attribute of model sets the status of variable is_kyc_verified to false. Here is the code of the User model and the ...
3
votes
1answer
80 views

REST API with Ruby on Rails and ReactJS

I'm currently working on building a simple REST API using Ruby on Rails. I noticed that a lot of the things I did were a bit redundant, especially the models. Just to clarify: I want this to be a REST ...
3
votes
0answers
28 views

Memory efficient Log Parser

I wrote this together for a test I'm doing that parses the Heroku access log. What I'm mainly interested is if this code follow common best practices and if there are any improvements I can make in ...
5
votes
1answer
66 views

Adding ports to a random list of IP addresses

I have created an application that I will be using for pentesting. It creates a list of random IP addresses, pings them, and adds ports to them (but it's not complete). It works exactly how it ...
4
votes
2answers
65 views

Counting numbers whose digits all go up or down

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
34 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
27 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 ...
4
votes
0answers
49 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 ...
0
votes
0answers
19 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
47 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, ...
1
vote
0answers
26 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
90 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
39 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
78 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've also separated the sections ...