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
5answers
46 views

Ruby array search, returning either a result with a good score or the last result

I have an array of hashes, each of which has two attributes: "title" and "Zscore". I want to return either the result of ...
-5
votes
0answers
12 views

syntax error, unexpected end-of-input, expecting keyword_end Error in Ruby [on hold]

I am by no means an experienced programmer. I am working hard to teach myself and am trying to learn ruby. I recently started a project trying to make a turn based pokemon style fight game. I'm ...
5
votes
1answer
47 views

Calculating protein mass

This question is part of a series solving the Rosalind challenges. For the previous question in this series, see A sequence of mistakes. The repository with all my up-to-date solutions so far can be ...
2
votes
2answers
27 views

Random distribution in Ruby

Below is a Ruby implementation of a random statistical event, based on a hash with the actual observed counts of outcomes. I'd be interested in feedback in particular on what techniques I might use ...
0
votes
1answer
24 views

Rails Grape API Endpoint optional params validation in update

I have the following rails grape api endpoint in the users resource: ...
3
votes
1answer
27 views

Semi-playable chess game in Ruby

I made a simple, semi-playable command line Chess game for my class exercise. At this point, this game can do the following things: Print out the updated board representation after every move ...
1
vote
0answers
27 views
+50

Reduce encoded length of UTF-8 encoded Ruby string in C extension

I'm writing a Ruby extension in C. It's a string processing module working on UTF-8 encoded strings only. One method, full_width_to_ascii!, converts full width ...
-2
votes
0answers
25 views

Saving email into txt file [closed]

I'm writing a little Ruby script to save email from a particular website into .txt files on my machine. The script is almost ready, but I'm not pretty sure if it is correct. Here it comes: ...
3
votes
1answer
40 views

Redirecting to the appropriate URL for some type of notification

I have a polymorphic notification model with action attribute. When user clicks on a notification he/she should be redirected to given page the notification refers to through notifiable. What is the ...
2
votes
2answers
50 views

Custom map on `Array`

I have the following problem: Given an Array, apply a certain method x to each Array ...
0
votes
0answers
28 views

Ruby beginner: class, instance variable, accessor, rspec [closed]

So I'm in the process of trying to recreate a board game called Ciao Ciao. I'm not anywhere near done but I keep getting stuck and would really appreciate some help. So far I've made the following 3 ...
1
vote
1answer
62 views

Ruby class to model (pre)historical Dates with (im)precision

I am relatively new to Ruby, having worked with Rails for about 8 months. For fun and my own education, I have written a Ruby gem (no Rails) that models dates with a precision (second, minute, hour, ...
3
votes
1answer
47 views

Using Ruby to record tasks

I started writing this program to get a better understanding of different aspects of Ruby. I tried to follow the ruby style guide here. What it's supposed to do is take the exercises/tasks you give ...
1
vote
1answer
59 views

Getting predicted values for a student report form

I have a situation where I need to predict the input values for a form used to create a new model. The model is a "class report" that a teacher submits for a student after their class finishes and the ...
4
votes
1answer
39 views

ActiveRecord selection, modified by optional parameters

I have an action method in my Rails controller which filters an ActiveRecord model depending on the submitted GET parameters. Rubocop complains that Assignment Branch Condition Size is too high: ...
2
votes
1answer
156 views

Weight-loss calculator

I have a table that holds a user's weight for specific days. In my weights_controller.rb index action I can show these weights - no problem. What I also want to ...
2
votes
2answers
45 views

A sequence of mistakes

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

CodeWars Solution to “Simple Elevator”

I am new to programming (less than a year), and I would like to improve. I solved a problem on CodeWars and copied both my solution and the top voted solution below. I listed specific questions after ...
5
votes
1answer
76 views

Convert to Roman numerals in Ruby

Challenged by Sandy Metz's newsletter, I've tried to implement this kata from exercism. However, my solution, which passes the tests, is quite a lot simpler than Sandy's solution. Ok, so she's using ...
2
votes
1answer
65 views

Rails validating enum

The Ruby on Rails framework doesn't allow you to validate enums submitted through a form in any sane manner. Evidently, enums are meant to be used to maintain internal application state, and are not ...
1
vote
1answer
92 views

Merging two hashes with the mean values of each key if both hashes exist

There are two methods, hash1 and hash2, that return hashes or nil. The hashes have the same ...
1
vote
2answers
93 views

Merge array of hashes, keeping duplicate values as arrays

I am working on a Ruby gem to pull data from the Wikidata API. The data is deeply nested, as it contains a lot of repetition. I have written a piece of Ruby (sans Rails) code that enables an array ...
4
votes
0answers
56 views

Electron Application with JavaScript Backdoor and Ruby Command-Line Listener

I have created an Electron Application with a JavaScript/NodeJS Backdoor and a Ruby command-line listener. I created this program for remote administration of my home computer securely using a new ...
5
votes
3answers
50 views

Client categorisation based on hourly payment

I am currently working on a small internal rating system for clients to be able to prioritise my work based on what client pays best. The input data is the hourly rate they are paying and based on ...
2
votes
1answer
19 views

Polymorphic event notification model in Rails

I have a polymorphic notification model. When user gets a notification he can get on the page of the notifiable to check out what happened exactly. For instance ...
5
votes
4answers
53 views

Two HTTP notification methods

I have two very similar methods, which make HTTP requests, the difference is that one makes PUT and another GET. Is there any proper Ruby way not to repeat the setup code and not to pass the flag ...
3
votes
1answer
31 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
16 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 ...
2
votes
1answer
38 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 ...
5
votes
1answer
43 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
3answers
160 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
99 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 ...
5
votes
2answers
84 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 ...
6
votes
3answers
463 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 ...
4
votes
1answer
59 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 ...
2
votes
2answers
39 views

Recursive categories fetch and view

I have categories and subcategories in my view. The code looks like this ...
3
votes
3answers
74 views

Sort array of hashes with nil values last

I wrote a method which sorts an array of hashes by given hash keys. The method should put nil values at the end. ...
4
votes
1answer
61 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 ...
2
votes
1answer
48 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 ...
4
votes
3answers
90 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 ...
4
votes
0answers
68 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
37 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
33 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
28 views

SQL vulnerability pentesting tool

I've written a program that scrapes websites for SQL vulnerability (it does not exploit websites, it just provides a list of possible exploitable sites). I would like some critique on what I've done. ...
1
vote
2answers
34 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
78 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
61 views

Find existing session

I have this method in my rails app: ...
3
votes
1answer
65 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
157 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 ...