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

Ruby - Methods with same structure in a DRY manner

Let's say that I have the following methods ...
-1
votes
0answers
26 views

Execution reach to timeout for a large number of records (90K) in Rails

I am using the records to render in view after fetching from database after modification. It is working fine for records up to 5000 but show timeout when try for 90,000 records. I run individual ...
3
votes
1answer
51 views

Countdown AppIndicator

I've decided to translate an old Unity AppIndicator I had written in C to Ruby, so I can practice coding with it (got a little bored with the completely beginner lessons I've been following, which I'...
1
vote
0answers
25 views

Service Connector abstraction for Ruby

My Rails apps need to connect to several external services to perform some functions. Now, I realize that some of the services I need might also be reused outside Rails (like in Capistrano ...
1
vote
2answers
42 views

Fraction class with documentation

I have never worked with Ruby before, and thought I'd start working on learning it. For my first little implementation, I have created a simple fraction class. It would be nice if someone would check ...
3
votes
2answers
36 views

Ensure continuous date range

I have two arrays dates = ["20161010","20161013"] values = [5,3] which represent dates and a view count. To display them in a graph, I also need the values ...
1
vote
2answers
26 views

Title capitalization exercise from The Odin Project

I just finished the book title class exercise for The Odin Project and I would appreciate some honest feedback for my code. The code is intended to be "test-driven learning", and therefore emulates ...
4
votes
1answer
65 views

Finding the indices where a selected player appears in a list of hashes

I have an array of hashes in a YAML file. When I run the code below it is VERY slow. My YAML pwsarr.count is about 2000. I am somewhat new to Ruby so I don't know ...
4
votes
1answer
37 views

The Odin Project - Project Ruby: Translating from English to Pig Latin

I just finished the pig latin translator for The Odin Project and I would appreciate some honest feedback for my code. The code is intended to be "test-driven learning", and therefore emulates test ...
3
votes
0answers
38 views

Achieving thread safety in a payment service library

I wrote this code a while ago, which is an excerpt of a payment service library: ...
4
votes
1answer
51 views

Marketplace checkout system

I was given the following code challenge as part of an interview process, unfortunately I did not get through to the next stage. Any advice on how I could improve would be very much appreciated. Here ...
1
vote
1answer
39 views

Skip invalid record and avoid execution break for invalid record

Here is the pseudo code used inside a Rails controller: ...
1
vote
1answer
47 views

Directed Acyclic graph implementation in Ruby on Rails

I have an implementation for a graph node class that I'd like to have function as a directed acyclic graph. The associations are roughly as follows ...
5
votes
1answer
78 views

Temperature converter app

I'm learning Ruby and as an exercise I decided to build this little temperature converter app (C to F, F to C, F to K, etc). Looking back at it, it's pretty much just a bunch of boilerplate code. Any ...
0
votes
2answers
50 views

Acquiring a hash containing a key and a value

I am new to Ruby and not familiar with a lot of Array features. I feel like this code can be written in a couple of fewer lines. The idea is: I have a ...
2
votes
1answer
53 views

Project Euler #1: multiples of 3 and 5 Ruby

Total newbie here and wouldn't mind learning from Rubyists to look at how I tried to solve this challenge. I started with 2 variables n which starts at 0 and total which is an array where I intend to ...
2
votes
1answer
131 views

Analyze Shakespeare's Macbeth parsing XML from web using Nokogiri

This is a simple Ruby program to analyze the number of lines characters speak in Shakespeare's Macbeth using Nokogiri and open-uri to parse a given url containing xml. I wrote this as practice getting ...
0
votes
0answers
15 views

Reading keyboard strokes using multiple input threads

I have a command line program which reads input one character at a time. The following code is working, and if I press three keys at once they will all be printed. There are four questions here: why ...
1
vote
3answers
25 views

Binary conversion app

I'm pretty new to ruby and programming in general. I had an idea for a fun little project that I could use to gain a little experience. I wrote a simple program that takes a 4 bit binary sequence (ie....
1
vote
0answers
45 views

Multi-way Tree organized alphabetically and search in preorder trasversal order

In attempt to create a k-ary or multiway binary tree sorted alphabetically at every deep, I created this class in Ruby to handle the order and search in a recursive way by the ...
4
votes
3answers
52 views

Burning logs - really simple text game

What I have I am a bit advanced PHP developer, but now I'm going to college where we are learning Ruby. We got the first homework and I did it. But I wanna make great code - so I looked for standards ...
0
votes
2answers
84 views

Most common letter in string, trying to use idiomatic Ruby

The task: Write a method that takes in a string. Your method should return the most common letter in the array, and a count of how many times it appears. Model solution: ...
1
vote
3answers
83 views

Determines whether a number is a power of 2

The task: Write a method that takes in a number and returns true if it is a power of 2. Otherwise, return false. You may want to use the % modulo operation. ...
0
votes
2answers
39 views

Find indices of first pair of numbers that sums to zero

Here is the task from a beginner's course: Write a method that takes an array of numbers. If a pair of numbers in the array sums to zero, return the positions of those two numbers. If no pair of ...
3
votes
1answer
60 views

Outputting years with no repeated digits

I'm working through a course now, and was tasked with the following: Write a function, no_repeats(year_start, year_end), which takes a range of years and outputs ...
1
vote
0answers
18 views

Project Euler - #5 smallest multiple [Ruby using a hash table]

Why will this code will work for a smaller multiple like 10 but time out for anything over 13? Can this code be refactored to work for larger numbers? (p.s. I have an alternate solution but wanted ...
4
votes
1answer
59 views

A Twitter bot that fetches Forecast.io data and tweets out the current weather with text and emojis

This is my first attempt at creating a Ruby script. I set up a Cron job to run this script every hour. I'm requesting constructive critiques and suggestions for making this better. Sidenote: I've ...
1
vote
1answer
46 views

Multiway Ruby conditional

I'm a little unhappy with the look of this "flexible" way of dealing with errors from an API in Ruby: ...
1
vote
2answers
49 views

Find numbers with same number of divisors

I tried to resolve this task: The integers 14 and 15, are contiguous (1 the difference between them, noticeable) and have the same number of divisors. ...
1
vote
1answer
51 views

Ruby: comparing two Arrays of Hashes and mapping one to the other

Can you help me to optimize my code for the following problem: An array of hashes named expected_tasks has tasks. Each task has a user that has to execute an action and contains fields. The ...
3
votes
1answer
61 views

Price rating approach

I'm pretty new to web development and I don't know if my solution is OK according to the best practices, considering performance and clean code. I have a Merchant model that belongs to a Price model. ...
5
votes
1answer
65 views

Next, greater permutation of digits of a number

Was looking at this question (which I initially misunderstood completely), to which Peter Taylor posted a good answer outlining a much better algorithm. For kicks, I implemented it in Ruby, but I ...
0
votes
3answers
26 views

Testing #initialize of class Author

I am trying to test #initialize of class Author: ...
3
votes
2answers
98 views

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. You have to create a function that takes a positive integer number and returns the next bigger number formed by the same digits: ...
3
votes
0answers
35 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 any ...
5
votes
2answers
37 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
25 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
34 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
46 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
37 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
71 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
88 views

Ruby Brainfuck interpreter

I recently wrote a simple Brainfuck interpreter in Ruby: ...
-4
votes
1answer
36 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: ...
5
votes
2answers
98 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
73 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... <...
5
votes
1answer
55 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: ...
1
vote
1answer
60 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. ...
5
votes
2answers
337 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
56 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 ...