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

Loading Authorization Permissions for Web Application

I've recently started on a decently large project, and I've run into a snag. I need to be able to allow an administrator on the site to define and construct permissions for everyone else on the ...
0
votes
0answers
27 views

Building an aggregated query

This code is for building an aggregation query with the Mongoid gem. All the syntax is Ruby hashes and arrays. I must split it into many small chunks, but it still looks terrible and easy to make ...
3
votes
2answers
76 views

Choosing a magic number between 0 and 9

I wrote a little script that asks the user to choose a number between the 0 and 9. Wile he/she is entering a choice, the program tells him/her if the number is too high and too low. Nothing fancy, ...
2
votes
1answer
25 views

Sidekiq worker in Ruby

I have worker code that looks like this: ...
-1
votes
0answers
8 views

Attribute Value Inheritance in Rails [closed]

We have a pattern in our code base where we have a parent model and a child model (a has_many/belongs_to relationship) and both the parent and child tables contain a field :foo. We then override the ...
0
votes
0answers
19 views

Simplicity decider

I was interested in the codegolf challange about simple text. The spec is: Write a function that from a text returns the non-common words. I assumed non clean input so I cleaned it before ...
6
votes
1answer
34 views

Sentence maker with thesaurus

I'm teaching myself Ruby by rewriting PHP solutions, such as this one. The program should match words in a sentence with a dictionary of synonyms and then make combinations with them. ...
3
votes
1answer
29 views

Small BM25+ implementation for probibalistic result ranking

I came up with this small implementation of an Okapi BM25+ ranker using Ruby. I cooked it up in a very short time so it's very simple but I'm trying to think whether there's a better way to write it. ...
4
votes
2answers
45 views

Longest lines of file descending

This is a challenge question from codeeval.com: Write a program which reads a file and prints to stdout the specified number of the longest lines that are sorted based on their length in ...
3
votes
2answers
54 views

Matrix class with lots of tiny methods

I have been following the advice to make tiny methods that does just one thing and does it well. I also have been keen on reducing or eliminating duplication as much as possible. But when a very ...
5
votes
2answers
41 views

The Geppy String: Regex vs Iteration

We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right. Return true if all the g's in the given string are happy. ...
3
votes
1answer
26 views

Ruby script that deletes servers from Red Hat Satellite

This script uses the Red Hat Satellite v5.4 API to delete servers which are read in from a file. The servers are listed in the file by hostname but the Satellite API deletes servers by ID number. The ...
1
vote
0answers
21 views

Monoalphatic and Polialphabetic cipher in Ruby

This code encrypts a text with mono-alphabetic and poli-alphabetic substitutions ciphers. For further info see: Mono-alphabetic/Caesar Cipher Poli-alphabetic cipher : ...
3
votes
1answer
36 views

Method that reserves a reservable entity and charges the user

This method works for what I need it to do, but I just don't think it's extremely readable, and could be abstracted into different methods. I have a feeling I'm going against some best practices. ...
10
votes
1answer
155 views

Robot toy simulator

I have already flunked the test with this code so don't feel bad for cheating any employer. I didn't get any feedback though just wondering what could have gone wrong. You don't need to get into the ...
4
votes
1answer
60 views

Balancing words

A word is balanced at the index if the sum of the alphabet positions of all the chars multiplied by the distance to the index is zero. This description is equivalent to the one given by ...
0
votes
0answers
34 views

Saving record payment data to respective tables

I have following action in the controller and am wondering how I can refactor it. ...
7
votes
5answers
720 views

Most common letter in string

Problem: 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. Note: I solved it with Ruby, but the ...
4
votes
1answer
51 views

Markov chain-based word salad generator

I like Markov chains. Last time I used one, I made one that generates words. This time, I made one that generates sentences, given a set of words and valid connections. This time, it's not weighted ...
2
votes
2answers
59 views

Parsing JSON string from HTTP request

HTTP request is made, and a JSON string is returned, which needs to be parsed. Example response: ...
4
votes
2answers
120 views

Calculating sum of smallest prime factors for 2 < n < 10**12

I am trying to calculate the sum of the smallest prime factors of n, where 2 < n < 10**12, and get the remainder of this ...
3
votes
1answer
38 views

Arrow test Ruby gem

I wrote my first Ruby gem, which is for testing code in the shortest way possible. Here's a usage example: require 'arrow_test' 1 + 1 # -> 3 arrow_test The ...
4
votes
1answer
53 views

OO coding style in short Ruby scripts

I've been using Ruby for about a year now, mostly for small scripts with uses ranging from data munging to DevOps tasks. However, I am not intimately familiar with OOP (I appreciate the functional ...
4
votes
2answers
90 views

Reversing a number in Ruby

I'm writing a function to reverse a number in Ruby. IE, 314159.reverse should return 951413. Here's what I have, which works: ...
4
votes
1answer
49 views

Brainf**k to Ruby interpreter — v3

Previous iteration. I think this is about as good as it's gonna get, but just for kicks, let's do one more round of iterations. As before, it's a very simple substitution from Brainfuck to Ruby, ...
3
votes
2answers
98 views

Euler 357 solution efficiency

I have a Ruby program which should solve the following problem: Consider the divisors of 30: 1,2,3,5,6,10,15,30. It can be seen that for every divisor d of 30, d+30/d is prime. Find the sum ...
4
votes
2answers
59 views

Decorator pattern for an application

I've created a decorator in my Rails application. However, the initializer has 3 params. Is this generally acceptable in decorator or should I refactor this or try a different pattern? ...
8
votes
1answer
119 views

Brainf**k to Ruby converter — v2

Previous iteration. You know, I think this is the fastest I've ever pushed out an update to anything. This is Version 2 of my Brainf**k to Ruby converter, and the generated code looks... Well, like ...
6
votes
2answers
402 views

Brainf**k to Ruby converter, written in Ruby — v1.0

I've seen a lot of Brainf**k interpreters in various languages. I decided that actually interpreting Brainf**k is too hard, so instead of that, I wrote a 'compiler' in Ruby that directly transcribes ...
3
votes
1answer
30 views

Consolidating a raw csv of two ids to grouped set of ids in json

The file I'm processing here is an outputted file from a Java library called duke. Its goal was go through all purchases made on a site and group them into a single customer. The output is a csv ...
-3
votes
1answer
32 views

Fetching shipment statuses for a user [closed]

I think the inherent relations in this query should be self-evident: ...
2
votes
1answer
36 views

Transforming class names to method names

I have a lot of filter classes which are named after the method names they filter by. For example: OrderByBestValueFilter corresponds to ...
3
votes
2answers
64 views

Parking lot and vehicle classes

The expected functionality is that a user/vehicle interacts with a ParkingLot and it allots the space in Park method based on ...
3
votes
2answers
107 views

Creating a user profile from an omniauth hash

I have this code that creates (or updates) a user from an omniauth hash parameter: ...
0
votes
1answer
33 views

Retry storing HTTP response into a variable until specific code

I want to keep trying to get response until its code is 200 or unknown yet. In first case it should be stored in response variable. In another case I should raise ...
7
votes
0answers
86 views

Debug statement remover

I've been fiddling around with some programs, and since most of them are for fun, I haven't bothered with little things like making the output non-verbose until I, say, put it here, for review. I was ...
2
votes
2answers
74 views

Collecting users' data as an array

I want to collect my users' data as an array: ...
2
votes
4answers
69 views

Combining two Arrays of hashes based on a hash key

I have two arrays of variable lengths: people1 and people2. I want to create an array of arrays where each inner array is a pair ...
4
votes
1answer
30 views

Selecting CPUs and memory in Vagrant

I generally like to be Rubocop-clean, but it seems like breaking up the first case statement will only make things harder to read. Any suggestions? ...
2
votes
2answers
73 views

Idiomatic Ruby FizzBuzz

Can anyone offer any criticism on the following at a simple FizzBuzz in terms of Ruby idioms or otherwise? ...
7
votes
1answer
59 views

Extensible FizzBuzz in Ruby

The title says it all. This is yet another FizzBuzz implementation where you can specify the words you want to use, though it autoselects the divisors as the first n primes other than 2, rather than ...
10
votes
1answer
98 views

Zork-style game engine (Specifically, a Cactus prototype)

So I'm one of those weirdos over here talking about making a game engine for text-based (think Zork) games. There was pretty recently another question by someone else working on the same thing, if ...
6
votes
2answers
108 views

Bank ATM program in Ruby

After reading a bunch of Ruby tutorials, I decide to write fake ATM bank software. I've tried to use OOP design and just want to know if I'm on the right road. ...
1
vote
1answer
22 views

Ruby script to deactivate or add users to database table

I have a Ruby script meant for some basic database tasks, such as add a user and deactivate a user. The end user can load up the script and follow the basic path of "Do I want to add a user?", or "Do ...
3
votes
1answer
46 views

Calculating IRR (Internal Rate of Return) in Ruby using recursion

Is there a way to improve this code? (specially how I built the recursion and the breaking out of the loops and conditionals) ...
1
vote
0answers
21 views

Searching through rows of paged grid until row is found or there are no more pages

I have a GWT Grid, using a pager, so pages of the grid (table) can be any number of elements long. I'm looking to iterate over every row of each page until I find a row with the matching text in the ...
4
votes
1answer
32 views

Monitoring and re-establishing a PostgreSQL connection

Within a complicated Ruby project, I need to monitor the connection to a PostgreSQL database, as answered here. I use a thread for this purpose. Every few milliseconds, I invoke "consume_input" which ...
5
votes
1answer
37 views

TicTacToe game in Ruby

I would appreciate any feedback you could offer. I'm self-learning, so I don't really know a "standard" that my code should be up to. I'm also not sure how to get rid of that bit of logic at the ...
2
votes
1answer
31 views

Reduce the calls to database for validations in rails

I was building a rails web, and used form object to separate the validation logics per form. I had to find_referral_code twice in order to store the user_id of referrer. I wonder how I can improve ...
4
votes
2answers
121 views

HackerRank challenge - index palindrome

I have a solution but it fails the performance for two tests. How can I speed it up? ...