Questions tagged [ruby]

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

Filter by
Sorted by
Tagged with
36
votes
2answers
2k views

It'th wabbit theathon

I don't know regex. I want to learn regex, but learning regex just for the sake of regex would be quite boring. So I decided to learn Ruby as well (which so far looks a lot like Python, which I'm ...
4
votes
3answers
536 views

TicTacToe game with functional AI in ruby - follow-up

A month ago I posted an earlier version of the game here, and got a great response, which was mainly about the structure of my code. I freed some time today and reworked the code from scratch. Things ...
21
votes
5answers
7k views

FizzBuzz in Ruby

I have this implementation of the FizzBuzz challenge in Ruby: ...
21
votes
1answer
2k views

Weekend Challenge: Ruby Poker Hand Evaluation

I'm late to this weekend challenge (sorry), but since it's all in good fun, I hope that's ok. I'm no poker player, though, so I may have completely overlooked something. The ...
17
votes
2answers
442 views

Count the occurence of nucleobases in DNA string

Inspired by this meta question I decided to take a look at Rosalind. Their first challenge seemed easy enough: An example of a length 21 DNA string (whose alphabet contains the symbols 'A', 'C', 'G'...
10
votes
1answer
781 views

Spell a given number in English

I wrote a program that will take a number from 0 to 999,999,999,999 and spell out that number in English. How could I improve the readability of my code? ...
6
votes
3answers
721 views

The Genetic Code

This question is part of a series solving the Rosalind challenges. For the previous question in this series, see Wascally wabbits. The repository with all my up-to-date solutions so far can be found ...
6
votes
2answers
1k views

Hackerrank challenge - Dictionaries and Maps

This is a solution for the Day 8 hackerrank.com challenge. The basic idea of the challenge is to create a mapping of names to phone numbers based on the the given input, and later look up the phone ...
15
votes
1answer
210 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, ...
12
votes
1answer
352 views

Multiplayer bowling in Ruby, with variable skill

This is a multiplayer bowling simulator in Ruby. It allows for variable skill levels, and produces weighted random results for each roll based on those skill settings. The methods are grouped in four ...
8
votes
1answer
375 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 ...
7
votes
2answers
1k views

Higher lower game in Ruby

I finished the Ruby chapter in Seven Languages in Seven Weeks. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely ...
4
votes
1answer
168 views

Mendelian inheritance

I started out with the Rosalind problems a while back. Turns out it's a great way to learn a new language. I'm still trying to learn Ruby, and while I haven't managed to use regular expressions as ...
4
votes
1answer
1k views

Validate if Sudoku is correct

Given a two-dimensional array, Sudoku class can create NxN Sudoku where N = size^2. Assume that the user gives only valid NxN matrixes for the constructor. Method <...
4
votes
1answer
635 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 ...
2
votes
1answer
109 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 ...
26
votes
4answers
14k views

Unit-testing a controller in Ruby on Rails

I intend this to be a general question on writing an effective set of test cases for a controller action. I include the following ingredients: Ruby on Rails RSpec: A testing framework. I considered ...
17
votes
4answers
1k views

Genetic algorithm for Clever Algorithms project

I wrote a bunch of Ruby code for a book project I've just finished. One criticism is that it is fine code but not very "ruby like". I agree my style was simplified for communication reasons, and ...
8
votes
3answers
13k views

Roman numeral converter

I'm writing a program to convert integers to Roman numerals (naively -- it doesn't know how to do the subtraction trick yet). What I have is functional, but it is not "Good Ruby". ...
14
votes
1answer
173 views

TicTacToe with AI in ruby - follow-up overload

I already posted this program numerous times, always surprised by the amount of improvement that is possible suggested by people here. Is it possible to make it even better, without nitpicking? At ...
20
votes
1answer
344 views

Are your servers down…?

If you came here because of the title, chances are your server isn't down. But if by some miraculous reason it is: A while ago, I posted a program that would ssh and ping all the servers at work. I ...
12
votes
1answer
299 views

Fractal generator

Refer to the help message and title of this post for what the code does. I'm looking for tips on: Efficiency: While the find-and-replace approach I have works perfectly fine and does so in a ...
8
votes
1answer
159 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 / ...
8
votes
2answers
3k views

Using I18n in capybara feature specs

Here I am trying to avoid hardcoding in flash messages by using I18n. Also, I have tried to use a CSS selector for submitting the form to make the tests less brittle (I don't really care that much ...
6
votes
1answer
766 views

Optimizing breadth-first-search code

I wrote code using some kind of breadth-first-search algorithm in order to find a path (any path!) from a start point to an end point. There are no weights/different distances involved from path-to ...
2
votes
2answers
3k views

Printing human-readable number of bytes

...
7
votes
2answers
931 views

A Ruby sorting program for multiple criteria

This code review expands on an earlier one that deals with generating a football table from match data. This review deals with ordering said table based on several criteria. Your opinions/...
7
votes
1answer
1k views

Pig Latin Translator

Could someone review the following code? ...
6
votes
1answer
426 views

Interface to a CSV dinosaur database

I have just finished with the first Ruby exercise on Level Up Rails, and wanted to get an idea on how I can refactor the code. You can find the original exercise on github - including the ...
6
votes
2answers
402 views

Server status checker

I've created a program for work that checks the status of all our servers quickly. What we use to have to do is ssh into each server manually. I'm looking for some ...
5
votes
2answers
277 views

Codingame: Great Escape bot in Ruby

(EDIT: I incorporated a lot of the feedback from the answers, and posted a follow-up question here: Codingame: Great Escape bot in Ruby - Follow-up) I started working on some code challenges at ...
5
votes
3answers
9k views

Multiples of 3 and 5 from Euler code challenge

I have implemented the first coding challenge on http://projecteuler.net/. I would love to get it reviewed by some expert rubyists! ...
4
votes
2answers
137 views

Print the length of words as input as a histogram with horizontal bars

Input A list of words separated by any number of spaces. Output A horizontal ASCII art histogram, where the n-th line is composed by as many asterisks (*) as the ...
4
votes
2answers
403 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
1answer
783 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
1answer
312 views

Concurrent stack implementations in Ruby (relative performance of mutexes/CAS?)

This code is very simple, but it is intended as an experiment in the relative performance of mutexes/CAS on different platforms. The latest version can always be found at: https://github.com/...
11
votes
1answer
981 views

Finding maximum deviation

It was a part of my coding challenge and the last one, but I failed because it failed to yield a result in two seconds for some of sample inputs (out of six samples, three passed but three failed for ...
8
votes
1answer
201 views

Calculating protein mass

This question is part of a series solving the Rosalind challenges. For the previous question in this series, see A sequence of mistakes. The repository with all my up-to-date solutions so far can be ...
8
votes
1answer
1k views

Custom grep in Ruby

I finished the Ruby chapter in Seven Languages in Seven Weeks. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely ...
8
votes
1answer
559 views

Outputting a .txt file from a .csv file

I wrote this little script in PHP a bit ago. It takes a .csv file and outputs a .txt file with certain data arranged in a "psuedo-array" looking format. I recently started messing around with Ruby so ...
8
votes
1answer
142 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 ...
7
votes
3answers
7k views

Caesar cipher in Ruby

I must implement a simple Caesar cipher class. Initializer takes two parameters - number of positions to shift the alphabet (integer) and the alphabet used (as string, not necessarily the standard ...
7
votes
1answer
3k views

SFTP Ruby script for downloading files from server

I have written this Ruby script to download some file from server using SFTP. Help me improve this one. Find the original script at this link ...
7
votes
1answer
1k 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 ...
6
votes
3answers
363 views

Wascally Wabbits

This question is part of a series solving the Rosalind challenges. For the previous question in this series, see Mendelian inheritance. The repository with all my up-to-date solutions so far can be ...
6
votes
2answers
426 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 ...
6
votes
3answers
1k views

Learning Ruby Caesar Cipher

I am trying to learn Ruby and made a simple Caesar cipher program and I was wondering if the following code follows the 'ruby way' or the way most ruby users would do it ...
5
votes
2answers
1k views

Simple TicTacToe game with AI in Ruby

What changes do you recommend from the perspective of structure, logic, etc? ...
5
votes
1answer
186 views

Game of Life in Ruby

I think Ruby is kinda interesting, so did this Game of life implement in Ruby. I am wonder is there is some magic in Ruby can let my code more elegant. I am a python coder and I think my Ruby kinda ...
5
votes
2answers
426 views

Validating a password format

How should I make this more Ruby-like or just "better"? ...