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

A circular buffer of size N [on hold]

My task: Implement a circular buffer of size N. Allow the caller to append, remove and list the contents of the buffer. Implement the buffer to achieve maximum performance for each of the ...
2
votes
0answers
20 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. ...
-1
votes
0answers
18 views

Is this rails symmetric encryption code correct?

My RoR application has a feature where a user can use their own password to symmetrically encrypt certain data (over TLS of course). Is the following code correct? ...
2
votes
2answers
65 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 ...
1
vote
1answer
68 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 return last element of list [on hold]

I was doing of one of codewars.com exercises and was asked to return the last element of the list. Here is my answer ...
-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
2answers
56 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
122 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
61 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
39 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
25 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
536 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
43 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
41 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
90 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
0answers
25 views

Is this code solid? If it's not why not? And how should the dependencies be managed? [duplicate]

I am very interested in following the SOLID principles of writing code, but for the life of me I consistently run into more questions than answers. One of the questions I have now related to the code ...
1
vote
2answers
47 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
97 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: ...
3
votes
2answers
57 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
45 views

Defaulting parameters to false

In my rails controllers, I am consistently using this logic: ...
3
votes
1answer
36 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
57 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
131 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
50 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
29 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
54 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
40 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
47 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
26 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
32 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
41 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
33 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
28 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: ...
1
vote
1answer
40 views

Parsing GPS data

Recently I sent this code snippet as CV attachment and I got simple answer - this code smells and we employ another developer. I'm new to RoR, so guys can you give me directions to refactor this code ...
2
votes
0answers
64 views

Binary Search Tree in Ruby

Binary Search Tree, with preorder traverse. What other methods should I add? How can I improve it? ...
3
votes
1answer
62 views

Bloom filter implementation using a BitArray

I am following the Wikipedia definition of the Bloom filter. My implementation uses the BitArray I created in Bit Array in Ruby using integer as a storage. An ...
3
votes
1answer
79 views

Bit Array in Ruby using integer as a storage

Ruby's Fixnum & Bignum can hold very large integers and automatically handle overflow. I decided to implement BitArray using an integer as storage. Please let me know what you think about code and ...
1
vote
0answers
23 views

Multiset implementation in Ruby -Take 2

This is a follow up to question. I fixed the issues mentioned in the answer as far as my understanding. The union and intersection now return new object instances with new implementation. I also wrote ...
2
votes
1answer
39 views

Multiset implementation in Ruby

I am trying to implement the wikipedia definition of a MultiSet. Need feedback on implementation. Also I am not sure how to implement cartesian product. ...
1
vote
1answer
40 views

Orange Tree simulator

I'm practicing SOLID principles and the concept of making a clear distinction between an object's private and public interfaces. ...
6
votes
1answer
76 views

Bowling scores in Ruby

A little while back, I wrote in a review of a Ruby bowling sim that I might try my hand at modelling the game myself, focussing on the funky "deferred scores" system. Since a2bfay, who posted the ...
-2
votes
1answer
62 views

SQL table: store “status” as integer vs as string [closed]

I've been around a bunch of projects where statuses are stored in the db as a integer, then mapped in the model back to a human readable string: ...
7
votes
1answer
84 views

Multiplayer bowling in Ruby (follow-up: injection, single responsibility)

This is a multiplayer bowling simulator in Ruby. It allows for variable skill levels, and produces weighted random results for each player's rolls based on those skill settings. This is a complete ...
1
vote
1answer
61 views

Testing after_save hooks in Rails 4.2 with MiniTest

I've recently started working on a new application in Rails 4.2.0-beta2. I've been using this as an opportunity to learn more about MiniTest, with a stretch goal of being as strict with myself with ...
1
vote
1answer
28 views

DRY up ivar assignment in Rails new and create controller actions

When creating a new model in Rails, I need to pass a bunch of other models into the view so I can define the correct associations. All I’m really doing here is querying the persistence layer for ...
3
votes
1answer
63 views

Circular Buffer implementation in Ruby

Does the implementation look correct? Did I miss something major/minor? ...
6
votes
2answers
68 views

How to avoid mounting SQL by concatenating strings?

I found myself mounting a query by concatenating strings. This just seems wrong. Any ideas of how to avoid this kind of situation? I'm using Rails 4, and I don't see how can ...