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
1answer
33 views

Fetching items from database with “Outstanding” status

I am fetching around more than 300000 items through a query: ...
7
votes
0answers
63 views

Trials, tribulations, and tributaries (Rainfall challenge)

Ok, the title is way too dramatic. But tributary is a nice word, and the alliteration was too good to pass up. Besides, konijn started it! This is a fairly simple Ruby solution to the August 2016 ...
3
votes
1answer
28 views

Small script to re-create a file indefinitely

I created a small ruby script at work to recreate a text file I use for a test in the Java application we are supporting. I'm still really new to the ruby paradigm and wanted to know if that small ...
3
votes
1answer
40 views

Merging hashes, summing values that have the same key

I'm trying to group by keys in an Array of Hashes in the following form and add their totals. Maybe with #map and #reduce/#inject. I know there is a more compact way to do this. Given I have ...
8
votes
4answers
2k views

Regex to enforce password requirements

I'm trying to write regex to validate the password for the given rule. Passwords must be at least 8 characters in length and contain at least 3 of the following 4 types of characters: lower case ...
1
vote
1answer
32 views

Using the BBC iPlayer API for managing TV programs

I have been learning Ruby by reading books and tutorials, and practising some problems on Codewars to level-up my new skills, when I had an idea for a little Ruby code project. It will store ...
0
votes
1answer
31 views

Getting all the master nodes in an elasticsearch cluster

I am trying to get all the master nodes in an elasticsearch cluster using this code. Can I reduce/simply this or optimize further? ...
0
votes
0answers
24 views

Ruby/Rails relationships for fashion categories

The premise of the site is for users to review outfits. So the main model of the site is a repository of outfits. Fashion changes every season so whether or not ...
3
votes
2answers
42 views

Find out if attributes are identical

I have an array of active record objects. All objects have an attribute result and the value of result can be either 'failed' or 'passed'. My goal is to find out ...
5
votes
4answers
78 views

Ruby solution to Project Euler Problem #4: Largest palindrome product

I've solved the Project Euler Problem #4, but I'd like some tips as to how to make this more efficient. I am a beginner to Ruby, so please be nice about the stupid stuffs (but still tell me about it). ...
2
votes
1answer
41 views

Simple object oriented design for an Temperature class

Design a temperature class for nurses to store patient temperature and the method of taking the temperature. How would you handle different units of temperature? Write a function to determine if a ...
2
votes
1answer
47 views

Simple object oriented design for an Allergy class

Build a system for entering and displaying the allergies that patients may have. The allergy will have its own set of symptoms reactions. The allergy will also have a spectrum of severity which ...
3
votes
1answer
42 views

Getting timeslots using a single query

I want to get latest time slots for 2 cases based on doorman true for false based on logged in user. Cases are: If doorman is true, the query will be the same if doorman is false, then I need to ...
1
vote
1answer
39 views

Arabic to Roman Number in Ruby on Rails

I am making a class method in ruby to convert from roman number to Arabic and vice versa. However the loop is run to match each character and again to match with roman mapper. Can I optimize the same? ...
2
votes
0answers
31 views

Unbounded knapsack solution with items of equal value

My solution correctly solves the problem, but I would like to optimize its performance. For a capacity of 7 and bars = [ 4, 1, 1, 2, 1], the output is 7. ...
1
vote
2answers
34 views

Nesting loops on same array but skipping same element

I'm having a bit of trouble trying to find a more Rubyist way to achieve the following. Essentially, I want to try and iterate over every element e and apply ...
1
vote
1answer
48 views

Conditional merge with Ruby to include a parameter if it hasn't been included

I have the following function, and I have a hunch it can be written more concisely in Ruby. ...
1
vote
1answer
29 views

Ruby object declared as constant [closed]

I have this piece of Ruby code: HTTPCLIENT = HTTPClient.new def read_page(url) HTTPCLIENT.get(url).body end The HTTPClient object is being created and ...
3
votes
1answer
53 views

Ruby FizzBuzz solution with Rspec test

My code makes the four tests pass, but I'm worried I'm missing something. Is the code too simple and not encompassing enough? I'm just beginning to learn so any feedback is welcome! Here's the Rspec ...
0
votes
1answer
19 views

Restricted file upload to remote the Ruby way

I am using a Rails web app on the machine webapp, from which I call an action, that pushes a file to a remote server backend. ...
5
votes
1answer
32 views

Adding product with attributes

I've been working on refactoring a piece of my code that allows a user to add items to their cart. Each product can also be added with different attributes. Thus if somebody adds the same product, ...
0
votes
0answers
35 views

Ruby thread pool implementation

I'm in the process of adapting the simple thread pool described here to my application. I'm new to concurrency in Ruby, but here is what I have so far: ...
9
votes
2answers
210 views

Luhn algorithm in Ruby

I'm learning Ruby 2.3 and I've tried to implement a function which performs the Luhn credit card verification algorithm on an input string, returning true if it ...
1
vote
1answer
36 views

Method to find posts in children categories

I use the gem act_as_votable to allow users to select categories they like. To get the categories a user likes: current_user.get_voted(Category) These ...
5
votes
1answer
164 views

Method to count unread messages

I currently use this method to count unread messages for a user (self here): ...
2
votes
3answers
117 views

Split string into 160-character chunks while adding text to each part

The send_sms_message method takes text as an argument. The length of text is unknown and can ...
1
vote
5answers
95 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 ...
6
votes
1answer
68 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
45 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 ...
1
vote
1answer
63 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
41 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 ...
3
votes
0answers
60 views

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 ...
3
votes
1answer
46 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
61 views

Custom map on `Array`

I have the following problem: Given an Array, apply a certain method x to each Array ...
2
votes
1answer
65 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
56 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
64 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
43 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
163 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
76 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
86 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
82 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
113 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
138 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
71 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
53 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
27 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
54 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
42 views

Install Ruby using rbenv in a bash script

I want to write an automated bash script for installing Ruby and Rails using rbenv, but I am getting session reload issues in the terminal. ...