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

learn more… | top users | synonyms

1
vote
2answers
18 views

Pretty way of keeping sensitive info out of a logged command string in Ruby?

I have a long command that I am building with shovels (<<), with the intention of eventually running system(command). I'd ...
2
votes
1answer
31 views

Complex method - flagged by codeclimate

I am a fairly new (RubyonRails) developer. I desire to improve my coding skills so I used climate to do some review on my code. It gave me a flag for this method that its complex. Is it characterised ...
3
votes
3answers
40 views

Math Equation Solver

I made this math script, where you enter an equation and it solves it for you. I was wondering what you thought of the code, and what I could have done better or what doesn't follow Ruby best ...
6
votes
1answer
59 views

Make Project Euler 27 solution idiomatic Ruby

I learned to program in Java and C# and in my free time I am using Ruby because it is fun. Unfortunately I have the feeling that I write Ruby code like I am making Java or C# code. I have learned to ...
6
votes
1answer
52 views

Binary converter and sufficient tests

I just finished writing a basic binary conversion class in Ruby. I'm curious to see if anyone has suggestions for improvements. In particular, I'm looking for the cleanest, shortest, most succinct ...
4
votes
2answers
37 views

Extracting ids out of arguments of different types

I'm building a Ruby API client. My brief is to extract ids out of various inputs and fetch the relevant data. It's working just fine at the moment but I think it's a little clumsy. My specs (which ...
5
votes
2answers
158 views

Concise nested statements

I really like the ruby ? : syntax for if else statements. However, I'm not sure how to do the following with a nested ...
3
votes
2answers
44 views

Adding time offsets to create future dates

How can I shorten this (working) code to create future dates in ruby for use as params in URLs? I'm doing: ...
2
votes
2answers
64 views

Transfer the format of an old string to a new string

First, I've extended the String class to detect uppercase and lowercase characters: ...
-3
votes
0answers
39 views

99 bottles of beer on the wall [closed]

I am going through Chris Pine's Learn to Program Ruby Book. One of his chapter 6 exercises is to write a program for the 99 bottles of beer on the wall song. I was struggling so I googled for some ...
0
votes
1answer
33 views

Managing several payment means in my Rails 3.2 app

I'm trying to manage several means of payment in my Rails 3.2 application. Let's say I have 2 means : Credit Cards & Bank Transfers (BIC), working with 2 different payment providers. Those means ...
0
votes
2answers
107 views

Tic-Tac-Toe implementation where computer should not lose

I have implemented Tic-Tac-Toe so that human can play with the computer, where the computer should never lose. I did a simple analysis before implementing, and I found out that there are certain ...
5
votes
1answer
55 views

Zombie Smack Down game

So about a year and a half ago, me and my friend started on a game called Zombie Smack Down. It's a text based game written in Ruby. But we were both really new to Ruby when most of it was written. I ...
6
votes
2answers
59 views

Building shape based on user input

The purpose of the below code is to build a shape based on the user input, specifically: Prompt the user to enter a shape - either a triangle or a square Determine which "texture" to use for the ...
5
votes
1answer
59 views

Need reviews for impacts of dirty bug fix

I was having a hard time with bug logstash#665. Hope they will fix it some day, but sparc/solaris support is probably not on top of their priority list. For further reference, original error is: ...
5
votes
3answers
87 views

Converting KML/XML to Javascript

So, I have the boundaries of every states in the US, from the google map KML file. This KML file is actually a XML file. I'm converting this file to a JS file compatible with google map in order to ...
7
votes
4answers
183 views

Adding intervals to an interval store

Write a program to do addition of intervals to an interval store. An interval is represented by an array of two elements - the lower and the upper bound (you can assume integers). Assume ...
4
votes
1answer
49 views

Refactor Ruby code from Hacker News API. Trouble parsing the JSON data

I made a command line Hacker News reader in Ruby that pulls the latest 10 stories from HN and allows the user to cycle through them or open them with Launchy. This was to play around with Ruby and ...
3
votes
1answer
72 views

A Ruby crawling for emails on websites given by google API

I'm trying to build as stated in the title an app which crawls a website to find the emails that it has and then I want to print them. Also I want to allow the user to type in the console false when ...
1
vote
1answer
56 views

A Ruby string analyser

I wrote this script for a code challenge on TreeHouse. I already submitted my code, but I am looking for an after the fact feedback. The challenge was to open a file of text, remove specific words ...
-1
votes
2answers
56 views

Efficient way to sort a formatted array (Chris Pine book, ch 7)

I'm on chapter 7 of Chris Pine's book, trying to work on the last exercise in that chapter. This code works fine, but I'm wondering if there is a better way to do this... ...
4
votes
2answers
83 views

Article voting schema

System I'm building has Users and Articles. Users can upvote/downvote Articles and cancel their votes if they want to. Each vote changes article's score. Score equals to sum of all vote values ...
4
votes
1answer
81 views

Ruby script to load xlsx files into mysql db

I put together this Ruby script (1.9.3) to load data into MySQL from many xlsx files that contain data entered by people. These files typically have many illegal characters and it has been difficult ...
3
votes
2answers
63 views

Rails refactoring has_many

I have a RoR 4 app, and its model have these associations: ...
3
votes
1answer
169 views

My first controller rspec test

I'm just started learning TDD with Rails and RSpec. This is my first test for controller. Just plain RESTful UserController that responds with JSON, so it has no new and edit methods. Please review it ...
6
votes
2answers
114 views

Speed up long running Ruby code

I'm running code which works fast locally, but when it's on Heroku it's slow. Heroku says this is because there is less memory and CPU power on my hosting than locally. I'm trying to rewrite my code ...
4
votes
1answer
72 views

Ring buffer - can I do any improvements?

I was just reading about ring buffer the other day and I was fascinated by how simple yet efficient it is. So I've implemented a ring (circular) buffer in ruby and I'm just wondering if there's ...
9
votes
2answers
114 views

A Ruby implementation of derangement (secret santa) algorithm

A secret santa gift exchange is a game where each player is randomly assigned a person to whom they anonymously give a gift. The algorithm is referred to as Derangement. For example, given the ...
5
votes
1answer
63 views

BinarySearch Kata in Ruby

I've just completed this binary search kata - which has some weird requirements - and I spent a little while "cleaning" up my code and making it more compact. I would appreciate some feedback on the ...
7
votes
1answer
118 views

ActiveRecord extension to find next / previous record(s) in one query

I just wrote this gem order_query to find next or previous records relative to the record assuming a (possibly complex) ORDER BY over the records. For example, this ...
32
votes
3answers
964 views

Chat bot for posting recent answers

I am the half-robot side of syb0rg that will be posting the recent answers of Code Review to the CR Answers chatroom. Here is the list of review suggestions I would like, in order of preference: ...
1
vote
1answer
61 views

1-line conditional statement needs to be trimmed down

I have this conditional statement with use of regex: ...
3
votes
2answers
69 views

Readability and cyclomatic complexity of this Ruby code

I consider this two options exactly the same. I prefer the first one but I'm not sure if it's better the second option in terms of cyclomatic complexity or readability. Assuming that this is not pure ...
10
votes
2answers
111 views

How can this Ruby format analyser be improved?

I have a requirement to validate file names related to architecture after they are uploaded. Once they have been uploaded I must warn the user if the file name is not standards compliant. What's in a ...
3
votes
1answer
54 views

Creating a pure Ruby object (PORO) to email files in a Rails application

I wrote a service object that emails a list of files to a list of email addresses. I am unsure about my emails method. It splits a string into an array of emails. ...
7
votes
2answers
80 views

Game object structure

So, to those of you who have ever looked at game design before, I'm interested in what you think of my approach. I'm trying to write a Minecraft server in Ruby as an educational project and I've hit ...
-2
votes
2answers
65 views

Remove leading, trailing and repeated dashes from a string [closed]

How do I refactor this? '-hello--world-'.chomp('-').squeeze('-').reverse.chomp('-').reverse # => 'hello-world'
5
votes
1answer
67 views

Quicksort implementation

I put together this implementation after playing around with various partitioning- and pivot-strategies, and it runs fine. I wrote this off a version which seemed a bit different from the majority of ...
5
votes
1answer
106 views

Converting between Fahrenheit and Celsius

I'm learning Ruby and working through some exercises. I completed the following exercise without truly understanding why and how it works. I know that's an embarrassing thing to say but I feel like my ...
7
votes
2answers
120 views

Generate permutations with symbols

Goal: Create a combination of emails based from inputted first name, last name, middle name, and a domain. Add in common separators. Then I'll check which one is correct with the rapportive API. This ...
10
votes
3answers
280 views

Proper capitalization for book titles?

I'm working through some exercises to sharpen my Ruby skills. The following code is how I solved this particular question. I'd like to know what other developers think of this solution. I'm self ...
1
vote
1answer
60 views

Calling a Class Method on a Module

I have a module (in file dialect.rb) defined as such: ...
1
vote
1answer
85 views

Ruby html href parser working slow

I wrote this simple HTML parser in Ruby. Basically I have a folder that has files. Every file has crawled web pages. The only addition within these files is before the HTML content there is a page ...
2
votes
1answer
46 views

Refactoring a String Calculator

I've refactored the string calculator kata as much as I could and tried to maintain single responsibility. Is there anything I could factor differently? The specs can be reviewed here. ...
6
votes
2answers
442 views

How to dry up this code without meta programming?

I have a ruby code segment which I need to DRY up. Following is the code segment. ...
9
votes
2answers
140 views

Cash Register Kata

The Setup This kata is a spin on the old backpack problem. Please give feedback on both the kata itself as well as my solution. I'm not sure if the kata needs to lead the student more or if this is a ...
3
votes
2answers
107 views

Removing list of words from a text file in Ruby

I have two files. File 1. Has a list of all the dictionary words File 2. Has a list of all prepositions. I want to remove all the prepositions from the dictionary. I want to reduce the number of ...
2
votes
1answer
99 views

Refactoring a Delimiter

Is there a more cleaner approach to this? I'm doing the String calculator Kata posted by Roy Osherove. I realized that my calculator has no way of clearing out a previous expression after calling add. ...
2
votes
3answers
119 views

Reduce cyclomatic complexity

How can I reduce cyclomatic complexity of validation and refactor it better way? ...