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

learn more… | top users | synonyms

4
votes
1answer
45 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 ...
1
vote
1answer
36 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
76 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
33 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 ...
3
votes
1answer
38 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 ...
2
votes
2answers
69 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: ...
-2
votes
0answers
29 views

Vending machine method [closed]

I have a big number of nested iterations in my method: ...
4
votes
1answer
46 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
83 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 ...
1
vote
0answers
28 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
118 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
399 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 ...
2
votes
0answers
23 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
29 views

Fetching shipment statuses for a user [closed]

I think the inherent relations in this query should be self-evident: ...
2
votes
1answer
34 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 ...
2
votes
1answer
48 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
92 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
31 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 ...
6
votes
0answers
79 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
70 views

Collecting users' data as an array

I want to collect my users' data as an array: ...
2
votes
4answers
67 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
72 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
58 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
90 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
98 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
40 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
20 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
28 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
35 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
29 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
101 views

HackerRank challenge - index palindrome

I have a solution but it fails the performance for two tests. How can I speed it up? ...
10
votes
1answer
62 views

Analyzer for randomly generated names

I recently wrote a name generator that uses a DTMC underneath (I asked about it here) and, since I'm not entirely confident I did it right, I wrote a script to check my code, or at least its output. ...
3
votes
0answers
40 views

Using Nokogiri to scrape Oscars winners from Wikipedia

I am scraping a Wikipedia page, getting info from that page and instantiating a new object with the information collected: ...
4
votes
1answer
101 views

Password Attacker (Google apac test problem)

Original Problem Short Summary: Given a \$M\$ possible characters all of which must be used at least once, find the number of possible combinations of length (exactly) \$N\$. The ...
7
votes
2answers
89 views

BotClean challenge

I'm going through the artificial intelligence domain at HackerRank. I'm very new to this domain and I really need a guide on how should I minimize the number of ...
8
votes
3answers
249 views

Sums of some array elements

I'm doing an archived MOOC at the moment which introduces Ruby programming. There are some assingments, yet no solutions and since the MOOC is over no one will correct those (+ the forum is down) I'm ...
8
votes
1answer
76 views

RPN calculator with interactive and non-interactive modes

While writing this review, I edited the code until it became something quite different from the original. In addition to the issues I mentioned, I ended up adding features: More operators / ...
5
votes
1answer
39 views

Formatting a price string

I'm formatting price string with the following method: ...
15
votes
1answer
92 views

Name/word generator using DTMC in Ruby

I just wrote a basic DTMC algorithm focused on generating names, though it could be used to generate lots of other things. It's designed to be run from the command line, so input is taken from a file, ...
4
votes
2answers
196 views

Simple Password Utility

I am somewhat new to ruby (but not to programming) and I want to develop a small web-app with Sinatra. I started creating a small password utility script that hashes and secures entered password. I am ...
11
votes
2answers
136 views

Did not pass the interview about an RPN Calculator

I recently received a simple interview assignment as to implement an RPN calculator in Ruby. The program takes user input and quits when the user presses 'q'. I did it in under 30 minutes and was ...
5
votes
1answer
84 views

Super2048 (Google apac Test Problem)

This is my second try at writing Ruby. Stylistic feedback is very much appreciated. The problem: 2048 is played on a simple 4 x 4 grid with tiles that slide smoothly when a player moves them. ...
6
votes
2answers
61 views

Bubble sort in Ruby

For practice, I tried implementing Bubble sort in Ruby. I wasn't very sure how nested for loops would look like in Ruby. Is this the 'right way' to do this in Ruby? I found this question, but it looks ...
5
votes
3answers
108 views

Finding the Nth prime

I'm going through some of the problems over on exercism and we were asked to write a program that finds the nth prime. I know Ruby has a Prime class that handles that but the exercise doesn't allow us ...
5
votes
1answer
71 views

Sort a scrambled itinerary (Google apac test problem)

This is my first time writing ruby - and I was mainly hoping to get some feedback and stylistic pointers. The algorithm is pretty straight-forward, since Google guarantees airports aren't repeated I ...
7
votes
1answer
110 views

Creating a Wrapper for CSV Data

I am trying to complete a Ruby coding exercise. The specifics of the excercise can be found on a the level_up_exercises GitHub repo. This repo also contains the CSV file used in the exercise. I ...
2
votes
0answers
46 views

Error handling for Stripe credit card processing

I have a rails application that uses Stripe for credit card processing. Currently several exceptions are being handled anywhere a transaction takes place. The code below is being used currently in 11 ...
1
vote
1answer
39 views

Manager for customer billing and subscriptions in Rails

I'm looking to get rid of a couple dependencies that I have a sneaking suspicion are present in the code that I'm writing. Right now I have a service class that manages my subscriptions for part of ...