Ruby is a multi-platform open-source dynamic object-oriented interpreted language created by Yukihiro Matsumoto (Matz) in 1993.

learn more… | top users | synonyms

5
votes
2answers
177 views

Count cars passing in opposite directions

The problem comes from codility, whose coding problems I'm starting to enjoy as their evaluation criteria really looks at runtime. Task description A non-empty zero-indexed array ...
4
votes
4answers
51 views

Validating a Collection of IPv4s

I have a method within a class that validates all proxy addresses are valid on initialization. I've tried to refactor this a bit, but this seems to be the best I can do. Any suggestions and/or tips as ...
9
votes
2answers
76 views
+50

Making kexec reboots less painful

kexec is a way for a Linux kernel to directly boot another Linux kernel without going through the usual BIOS startup sequence, which can take several minutes on enterprise servers. The big problem ...
-6
votes
0answers
27 views

Ruby classes implementation by example [closed]

I'm trying to learn Ruby by examples and exercises. Code a Ruby program that simulates a Hotel room lot. User will enter, issued a ticket, exit and of course pay. Basic Required Scenarios: User can ...
7
votes
1answer
39 views

Controller action to process orders and payments

I'm trying to reduce the if statements and simplify this create action. ...
6
votes
3answers
283 views

Towers of Hanoi

I am just learning how to code in Ruby now with no prior experience. This is 3 towers of Hanoi where the user selects where to choose from and where to go with each disc, and not to have a bigger disc ...
2
votes
2answers
40 views
0
votes
1answer
112 views

Project Euler - Problem #11 - Ruby

As a beginning Ruby programmer I implemented a solution for Project Euler, Problem #11. (The problem is described in the comment below.) I'll be grateful for any suggestions for improvement ...
2
votes
1answer
49 views

DRY-ing up some rspec

I have an rspec spec test that has two sets of the same tests (from 24 Pull Requests). I thought I'd refactor the spec whilst I fixed something else. Normally I just do a basic ...
4
votes
2answers
47 views

Rendering a selection box for 50 states

I was creating a Rails form where users have to enter their state. I ended up creating a select tag which is really, really ugly. I'd like to think there's a better way of writing this. ...
0
votes
2answers
57 views

Factory Girl in Rails

I have a FactoryGirl page that generates same data but in two different languages. The variable names are the same. How do I write it in the smartest way possible without having to write a huge bunch ...
1
vote
3answers
74 views

Refactoring RSpec/Capybara tests

Is there a better way of representing this RSpec code on Rails using Capybara? There are three scenarios only for when the sign up validations fail so is there a better way of representing them ...
2
votes
3answers
68 views

URL resolver for Users, Lessons, and Series

My Resolver.resolve class returns a hash of objects and I would like to return a specific object if it exists. Is there a more concise way to write this? ...
3
votes
2answers
57 views

Reservation validation

I got a Reservation model that has reservation_start and reservation_end. Then I have the ...
2
votes
2answers
50 views

CSV File Parser in Ruby - Attempt No. 2

The following is my second attempt at a basic CSV parser in Ruby. I've addressed suggestions that I've got for my previous version here. I have omitted all test cases - the code listing would be too ...
1
vote
0answers
38 views
1
vote
1answer
52 views

Reduce memory use for a property geolocator

I have to run a script against 40 million objects in my database: I wrote the script and I want 10 instance of it so I process my objects faster. The goal is to find all the neighborhood for each ...
0
votes
1answer
50 views

Avoiding Duplicates in a Ruby on Rails Factory Girl Factory with Fake

I have a Factory Girl factory that needs to generate a unique name using Faker. Unfortunately, Factory Girl generates duplicates relatively frequently, which causes intermittent test errors. I ...
4
votes
2answers
71 views

Ruby object oriented Snakes and Ladders implementation

I'm not a beginner to programming, but I am to programming in OOP (effectively at least). So to learn better I wrote an object oriented game of Snakes and Ladders. For background, see this question. ...
2
votes
2answers
85 views

Multifunctional Monty Hall Simulator

Based on this question on math.SE regarding probabilities in variations on the Monty Hall problem, I cobbled up a simulator in Ruby to give myself an introduction to the language. Since this is my ...
0
votes
2answers
106 views

Multiples of 3 and 5

Project Euler problem #1: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples ...
-1
votes
0answers
13 views

Ruby: using .send within a method behaves differently than calling it outside [migrated]

I'm trying to write a little snippet for my Rails app that checks if any tags are present for an object. I have the following code: ...
-1
votes
1answer
61 views

Feeder for returning an array of items rated by users

Feeder is in charge of returning an array of items rated by users (feed). If there is a watching user (...
3
votes
1answer
142 views

CSV File Parser in Ruby

The following is my Ruby attempt at a (very) basic CSV file parser class, inspired by an exercise from the book Seven Languages in Seven Weeks. I'm a Ruby novice and will be grateful for any ...
3
votes
2answers
73 views

Snakes and Ladders random world generator second implementation

The following is an implementation of a random world generator for the classic Snakes and Ladders game. This is a follow up to this question, where I reviewed my own original implementation. I am ...
4
votes
1answer
49 views

Snakes and ladders random world builder

I wrote a random world generator for the classic Snakes and Ladders board game. Snakes and Ladders is a dice game played over a grid, usually 10x10. You win by reaching the last square first. The ...
1
vote
1answer
33 views

Getting s3 objects with Rails

I have been using aws-sdk gem with Rails, for uploading and downloading objects. I believe it's working fine. Demo code: ...
5
votes
2answers
539 views

Should a class own the responsibility of converting an incorrect data type?

The ElectricalEngine class responds to the horsepower message. Because efficiency is calculated in percent a programmer can mistakenly initialize it with an integer ...
3
votes
0answers
52 views

RubyWarrior beginner epic Solution

This is my RubyWarrior Solution. I think RubyWarrior is well known to Ruby coders. I am starting to learn Ruby and I would appreciate some help from you to improve the organization or the mistakes ...
1
vote
0answers
55 views

Handling hours, minutes, seconds

Basically I wanted to make a generic class for parsing time codes and dealing with small units of time. I have tried to keep it very simple (small API) and 0 dependency (apart from RSpec). Some ...
6
votes
2answers
108 views

Generating non-repeating random integers in a fixed range

I was working on the "Robot Name" exercise over on exercism.io (neat site, by the way), the gist of which is: Generate random, unique strings that match ...
1
vote
2answers
62 views

Deserialize JSON Strings Directly into Models?

I have Ruby models which are populated from the responses of API calls in the following way: JSON.parse converts the response to a ...
2
votes
1answer
251 views

Refactoring a Crawler

I've recently ported an old project and made it object-oriented. However, I've noticed that rubocop points out the following status: ...
4
votes
2answers
68 views

Slowly working word counter

I have a problem where, given N terms, the task is to find the k most frequent terms from given N terms. My code is correct, but I have a time limit 10 seconds and my code doesn't pass. Constraints: ...
1
vote
4answers
52 views

Defaulting parameters to false

In my rails controllers, I am consistently using this logic: ...
3
votes
1answer
37 views

Can this bash shell script that checks for rvm ruby versions be improved?

As it is going to be used as part of some automation and not just at the command line I was wondering if it could be improved at all. Improve would mean any of: handle sad cases better handle ...
2
votes
0answers
62 views

Functional Game of Life implementation in Ruby

We ran a Code Retreat day at Hacker Paradise this Saturday, and I was pretty happy with my eventual solution. It's written in Ruby, but would work reasonably well in JS/CS and is (hopefully) ...
7
votes
3answers
142 views

Counting all pairs that differ by k

Given an array of numbers and another number k, how can I find the number of 2 elements such as their difference is equal to k? ...
0
votes
4answers
47 views

Finding powers of multiple array pairs

I'm doing a challenge on TalentBuddy that requires you to find the powers of multiple array pairs. Since I got the solution right, but not fast enough, I decided I'd ask for help here. ...
3
votes
3answers
53 views

Calculating change based on input

I decided to make a program that calculates change, based on an input. My code is extremely long, and I would like to know how I can fix this. ...
3
votes
2answers
33 views

Ruby infixed math parser

It only does expressions with 2 operands yet, but I'm wondering if there are any ways I can improve this: ...
4
votes
1answer
62 views

Ruby script to create git repos

I wrote my first ruby script, by this tutorial. It creates a local and remote git repo. I have been working for about 3 years with PHP, and somehow I find that my ruby script looks incredibly ugly. ...
3
votes
1answer
41 views

Hide content unless an array contains at least one non-empty string

I have an array of hints. Sometimes, this array could contain an empty string. Occasionally, the array might contain only empty strings, in which case I want the whole block to be skipped. This is ...
4
votes
1answer
49 views

Orthodox Easter calculator

I have code for calculating the date for orthodox Easter and it makes me cry when I look at the if-else part. Please give your ...
3
votes
1answer
31 views

Generating a complicated data structure in a more efficient manner

I need to convert some CSV data into a format recognizable by some old script my work uses. Changing the format is pretty much out of the question. So I've written this: ...
2
votes
0answers
28 views

Directions to refactor class for GPS track points

The story started here (Parsing GPS Data) and continued here (Class for median filter) I've done a lot work and faced new questions. In short - I made: Classes for parsers. TrackParser and ...
1
vote
1answer
39 views

Building query for search engine

I'm writing a basic search engine for my website. It works but I'm really unhappy with the code. I know it can't be improved but I'm lacking some experiences here. In my params from my search I get: ...
1
vote
1answer
43 views

Modify a method on the fly in Ruby

I have about a hundred Rake tasks that are creating Rails models for me from a legacy datafile. Each task shares some setup and teardown code; all that sets them apart is the code in the middle. For ...
2
votes
1answer
34 views

Class for median filter

I'm new to ruby, later I asked about ways to refactor code (Parsing GPS data), one man gave me direction, so I made class for Median filter and it will be great to read review for my work. What guys ...
2
votes
1answer
36 views

Mixing Watir::Browser into RSpec

In my previous Watir question I was making a module with session_FF accepting a block. Now I want to make the same but via RSpec. Here is my try: ...