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
8 views

Install ruby using rbenv in bash script

I want to write an automated bash script for installing ruby and rails using rbenv. But I am getting issue of session reload in terminal. My bash script:- ...
0
votes
0answers
10 views

Converting from a madlib program using hashmaps to using 3 different arrays to hold the noun, verb, and adjectives

Using erb and Sinatra, I need to make an array of each variable that can be added in, [noun], [verb] and [adjective], allowing me to return the number of each there are and create the appropriate ...
-1
votes
0answers
37 views

A long form to collect business information

I have a long form which includes many nested forms. I have tried to use partial but I believe partial is not working, and the object is not being transferred there. Any help with this will be ...
1
vote
1answer
21 views

Refactoring random number generation

As I'm learning Ruby I wrote this little program to generate a "nice" number randomly (like 4747, 6969, etc.). As I'm currently breaking the "do not repeat yourself" rule, how would you refactor the ...
0
votes
0answers
27 views

Ruby Sort Hash for same value [on hold]

I have hash like hash = {"n"=>5, "a"=>4, "h"=>3, "m"=>3, "y"=>3, "f"=>2, "r"=>2, "i"=>2, "e"=>2, "d"=>2, "s"=>2, "z"=>5} now i ...
4
votes
1answer
34 views

Generate dyamic 'week of' date range

I was in need of a method to dynamically generate a week range, so that the view reads something like "Week of May 16 - 22" and updates automatically. Here's the helper method I came up with, but I'm ...
4
votes
2answers
88 views

Guess a number, any number, between 1 and 10

I am learning Ruby and would like to know how I am doing as far as writing the actual code. Please keep in mind that this is my first Ruby script program, but I am trying to learn ruby in a very ...
4
votes
2answers
87 views

Sum of numbers that equal 100

I was asked to find all the numbers that added up to 100 with no duplicates in Ruby. I float between Python, GoLang, and Ruby in a day. I am always concerned if I am doing something in the most ...
0
votes
0answers
18 views

rspec: method mocks on objects returned by activerecord [closed]

If I have a controller that does this: class FooController def bar foo = Foo.find(id) foo.bar render text: 'done' end end What's ...
4
votes
2answers
74 views

Alternately taking elements from an array

Given the task of having to return an array that alternately takes elements from two arrays, what would be most Ruby way of completing the task? As of now, I have this code, but it doesn't feel very ...
5
votes
3answers
441 views

The Genetic Code

This question is part of a series solving the Rosalind challenges. For the previous question in this series, see Wascally wabbits. The repository with all my up-to-date solutions so far can be found ...
3
votes
1answer
52 views

Command line based email generation tool

Unfortunately due to my job I will have to leave out some of the information that is created by this generator, however I will be replacing it with another string of information. I have created an ...
1
vote
1answer
35 views

Recursive categories fetch and view

I have categories and subcategories in my view. The code looks like this ...
1
vote
3answers
59 views

Sort array of hashes with nil values last

I wrote method which sorts an array of hashes by given hash keys. The method should put nil values at the end. ...
3
votes
1answer
55 views

Determining whether a task is active based on many conditions

I wrote a Rails model instance method that checks many separate conditions, and returns a single boolean. It does not employ any nesting of branching structures. Each check has its own comments ...
1
vote
1answer
44 views

Expanding pixels in an image

Custom class Image takes a 2-D array of 0's and 1's upon initialization. Method transform returns a modified array by modifying 0's adjacent to a 1, such that ...
3
votes
3answers
78 views

Wascally Wabbits

This question is part of a series solving the Rosalind challenges. For the previous question in this series, see Mendelian inheritance. The repository with all my up-to-date solutions so far can be ...
3
votes
0answers
58 views

“Ymbirtt vs The Gilded Rose” Kata

The Gilded Rose Kata is a refactoring challenge, in which some frankly disgusting code is thrown at the developer, and they're told to make a small change to it. For reference, the (truncated) ...
1
vote
1answer
33 views

Old and new shouts controllers

I have a photo_shouts_controller.rb and text_shouts_controller.rb which both have almost similar implementations, and I would like to refactor it. I have implemented a refactoring but I am not too ...
2
votes
0answers
24 views

Stack based esoteric language interpreter in Ruby

For a while now, I've wanted to write a stack-based "Turing-tarpit". This is the perfect excuse to learn Ruby, which I have never used before, so I wrote Brain-flak. The language only uses these ...
0
votes
0answers
14 views

Ruby written SQL vulnerability pentesting tool

I've wrote a program that scrapes websites for SQL vulnerability, (IT DOES NOT EXPLOIT JUST SEARCHES) I would like some critique on what I've done, is there a way I can write the ...
0
votes
1answer
30 views

Rails create create default database records

In my application I have an accounts model: class Account < ActiveRecord::Base belongs_to :user has_many :invoices end The ...
1
vote
1answer
59 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
57 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
62 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
153 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 ...
4
votes
1answer
54 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
34 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
24 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
97 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
56 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
45 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
53 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
95 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
46 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
106 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
86 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
70 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
127 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
29 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
31 views

Skipping Google search results that point to certain sites

I have the following code that will skip certain URLs if needed: ...
2
votes
0answers
26 views

Custom bang! method and Rails validation

I have a model called booking. ...
1
vote
1answer
71 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
70 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
62 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 ...