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

Ruby: create a function that takes a positive integer number and returns the next bigger number formed by the same digits

I am taking on this challenge on codewars (sorry if this is not appropriate to ask). You have to create a function that takes a positive integer number and returns the next bigger number formed by ...
2
votes
0answers
15 views

Copy-on-write in Ruby

I need to return private collection and avoid calling code modifying them avoiding copying overhead if possible So I thought of returning copy-on-write arrays, hashes, and sets. I couldn't find ...
5
votes
2answers
27 views

Image batch processing in Ruby

I know a lot about Java, PHP and stuff, but I'm fairly new to ruby. I've written this script to look into the current working directory, get two parameters from the command line and then resize and ...
1
vote
1answer
14 views

Rails form helper to display email fields and their validation errors

I have a repeated pattern throughout my app that looks like this: ...
3
votes
0answers
23 views

Continuous median in Ruby

I have written a program in Ruby which calculates the median of a streaming set of numbers dynamically. For each number that arrives, the median is calculated for all the numbers that have arrived so ...
2
votes
3answers
38 views

Ruby function to find numbers whose sum of squares of divisors is a perfect square

I am doing a problem my buddy gave to me and I have my solution which works but needs to be optimised. I have tried to optimise it as much as I can with my knowledge but it seems there is still room ...
3
votes
1answer
29 views

Where should I put code which calculates stats which will be sent via mail

I want to send mail which will have day to day report. I have setup action mailer like this ...
6
votes
1answer
64 views

Self-modifying esoteric language interpreter in Ruby

I recently created Copy, an esoteric language, and wrote an implementation in Ruby. The language has only 7 instructions: copy <a> <b> <c> Copy ...
7
votes
1answer
66 views

Ruby Brainfuck interpreter

I recently wrote a simple Brainfuck interpreter in Ruby: ...
-4
votes
1answer
32 views

Getting last 5 leave requests for a user - where does the code live [closed]

I have a User model, a user has_many leave_requests, in the user model I have the following code to find the last 5 leave requests: ...
4
votes
2answers
75 views

Simple Blackjack program

I created this Blackjack program as a first attempt at Ruby. Would appreciate a code review to see if I am doing things the Ruby way (is there a better way to get user input?), using OOP correctly and ...
6
votes
2answers
65 views

Random name generation in ruby

I created this program as an exercise for me to learn ruby. It is a random name generator with a set of rules defined to generate pretty decent and usually pronouncable names. Ruby isn't exactly my ...
0
votes
1answer
49 views

Use SRP to refactor this Ruby Class

I have a class, and it does one thing, It adds numerals to the numerals array. In doing so it uses a number of private methods and has ended up looking a little bit sickening... brace yourself... <...
4
votes
1answer
45 views

ActiveAdmin: Hide a whole panel in a smart way

In order to only show relevant information to my users I want to disable the whole panel when all fields inside that panel are empty. Currently I do this hacky method to get to this result: ...
0
votes
1answer
37 views

Finding mongodb records in batches using mongoid

I want to get records in batches. But mongoid doc says to avoid using skip due as it can be expensive. I wrote this method to iterate through a large number records efficiently. ...
0
votes
0answers
29 views

Adding contacts to a list using AJAX, with handling for warnings and errors

Given a page that renders a list of contacts, and where you can add more contacts to the list via a form: When the user fills the form and clicks Add Contact there are 3 use cases that may occur: ...
5
votes
2answers
294 views

GCD of two numbers in Ruby

I am trying to implement a algorithm for the GCD of two numbers in a functional approach. Can this be improved further, also with regards to performance? ...
3
votes
1answer
51 views

Imported data from CSV successfully, but slow

Currently I am using the gem activerecord-import to seed more than 55,000 records into my database, and it works fine. However, it takes too much time. I am ...
4
votes
3answers
94 views

Loop through months (1-12)

I currently have this monstrosity: next_period = (((current_month + tax_period_months)-1) % 12) + 1 I want to get the month that is ...
2
votes
1answer
44 views

List enrolled users & show checkmark if all activities are complete

I'm a beginner with rails working on a rails 4 project to use with my students. Users enroll in lessons; on enrollment, four activities are created for each user (expositions, scrambled, dictations, ...
-1
votes
1answer
38 views

ruby rails 4 initialize and increment instance variables

I have been tinkering with various ways to clean this up and I was wondering if it is more ideal to break this into small methods or way to accomplish this on a single line? ...
2
votes
2answers
55 views

Simple ActiveRecord attributes encryption in Rails 5+

The task at hand was to ensure that certain columns in the database are encrypted in case the database data is stolen. I have a feeling that a lot can be improved here (naming, DSL, encapsulations) ...
5
votes
1answer
54 views

Parse sentences and calculate mathematical results

Content of task: Given a string of words and numbers. Extract the expression including: the operator: either addition or subtraction the two numbers that we are operating on ...
2
votes
2answers
83 views

Remove a key from list of hashes

Suppose my milestone is this: milestones = [ {state: 'unavailable'}, {state: 'arrived'}, {state: 'completed'} ] I want to remove all the ...
6
votes
2answers
106 views

Parsing Day Range with Time in Ruby

I need to shorten/simplify this code: ...
3
votes
2answers
49 views

Ruby bubble sort algorithm

I'm just looking for constructive criticism of my Ruby implementation of a bubble sort algorithm. ...
-1
votes
1answer
29 views

Rails - Events fully booked [closed]

I'm building an events app using Rails. I've installed a code block in my controller to ensure that over-booking doesn't occur once the total number of spaces for the event have been allocated/booked. ...
-1
votes
2answers
45 views

Refactor to avoid cope repetition in loop with condition checking

I have snippet that really look ugly but I don't know how to refactor it: ...
3
votes
1answer
45 views

Formatting a phone number

I have a program that will format a phone number in this format: (###)###-#### ...
3
votes
2answers
38 views

Ruby Select uniq in one statement

I'm trying to implement some simple logic using rails. Code is working fine but its look uglier to me, could any one help me on refractor or implement in a efficient way. Context: Data hash ...
0
votes
1answer
8 views

Creating and sending two kinds of notification messages

I wish to get rid of using switch case with statuses twice in my code. But create_message function will be bigger in the future, so must stay and I don't want to ...
3
votes
3answers
83 views

Creating work notes

I've created a program that will create work notes for me, however, I've been under the impression since I started writing in Ruby that while loops are bad. How can ...
1
vote
2answers
60 views

Combine arrays and preserve ordering - but prioritize one array's ordering over another

I have two arrays and I want to combine them both in a manner similar to this: ...
5
votes
3answers
47 views

Marking loans as paid if the payments exceed the loan amount

I have a Rails app where Loan has paid attribute. Loan should be marked as paid if total sum of payments is equal or higher than loan amount_to_pay. Problem is that ...
1
vote
1answer
20 views

Rails query for all questions in tournaments that a user participates in

I'm new to rails and this is the situation I'm in: I have a User model that has many tournaments, a Tournament has many users ...
6
votes
2answers
124 views

Simple Ruby program: a + b = c

I am new to programming and I would like some feedback. This is my first ruby program that simply adds a + b. I know it's probably more complicated than it needs to be, but I wanted to implement ideas ...
3
votes
2answers
146 views

Check if a string contains a set of characters

I have written this piece of code to check if a string contains a set of characters, regardless of the order. Eg: 'ruby is best' / 'bysbe' => true Code: ...
3
votes
1answer
49 views

Rails UserHelper method

I need help cleaning up this monstrosity. Basically this is a user helper method that generates an array of cumulative user sign ups per week (start of week == Wednesday) starting 2016-06-15. So ...
6
votes
1answer
167 views

Emails, emails everywhere

My job entails me to send a lot of emails. I'm really bad at typing so I decided to create a program to do it for me. I've created an email generation tool (originally posted here.) I've changed ...
1
vote
2answers
57 views

Fetching items from database with “Outstanding” status

I am fetching around more than 300000 items through a query: ...
7
votes
1answer
94 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
2answers
46 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
54 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 ...
9
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
36 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
32 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? ...
1
vote
1answer
22 views

Preventing duplicate submission in Rails

I have a Rails app where doctors score patients on diagnosis - their score is the model Baseline. Each Baseline has a user id ...
0
votes
0answers
30 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
44 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
90 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). ...