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

learn more… | top users | synonyms

3
votes
1answer
18 views

Ruby Bot application [on hold]

I just want to know if this looks good. ...
1
vote
1answer
30 views

Better way of comparing integers

I wrote this class which is comparing some values, how can I improve its performance and maybe make it prettier? You can see at the bottom what type of data it requires, also the array size can reach ...
1
vote
0answers
6 views

Memcache Keys Management Class

I have written below class to manage Memcache keys. My Memcache keys structure are like: ...
5
votes
2answers
43 views

Item-based collaborative filtering

I wrote the following code using Ruby to compute item-based collaborative filtering (using Jaccard coefficient of similarity). I would appreciate feedback about any potential issues with the code ...
2
votes
1answer
36 views

Performance of Codility MaxCounter challenge solution

I'm doing some of the Codility challenges using Ruby. The current challenge is "The MaxCounter," which is described as: Calculate the values of counters after applying all alternating operations: ...
6
votes
2answers
35 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 ...
2
votes
4answers
66 views

How can I prettify blocks with more than 2 of each block?

Actually, I just have no ideas. How can I make breaklines to make it more readable? Can anyone suggest ways on improving this? ...
1
vote
0answers
27 views

Improving argument passing to dumb tasks

I'm becoming acquainted with ruby by taking some of my legacy shell scripts and rewriting them as .rb The pattern that is emerging is that I have a number of different dumb tasks, that do what they ...
1
vote
1answer
47 views

Replace outside comma with newline

I'm looking for a better alternative to replace insert + gsub. ...
3
votes
3answers
113 views

How would you refactor this case statement?

I've got this code in my ApplicationHelper file: ...
3
votes
0answers
49 views

Validating control structures in a Ruby chess AI

I'm trying to reimplement a bit of C code (the Micromax chess algorithm) as Ruby in order to run in a Ruby environment. It's mostly done, but I'm concerned about the control structures, for a few ...
0
votes
1answer
29 views

Store location with some excluded path

This code stores the last know location in the session. The location is not stored if it is one of the exceptions in the if statement. ...
4
votes
0answers
24 views

How to create a 'tee' command in Ruby for a Unix like pipeline?

I came across the question about creating memory-efficient Ruby pipe class with lazy evaluation. Some code is given to effectively create a pipeline of commands using lazy enumerators. I have been ...
3
votes
0answers
63 views

Refactoring eBay webform into a more structured pattern

I've been working with this code for quite some time, trying to figure out how I can break it up. It feels very clunky and unorganized. The code takes in a hash that comes from a webform and also ...
1
vote
0answers
39 views

Writing an MVC project for the first time - how close am I?

I've recently started programming (learning Ruby) and wrote a small game. Now I've started reading about MVC and am trying to refracture my code to follow that architecture. The only classes with big ...
2
votes
1answer
37 views

Unit-testing account transaction code

I'm playing with unit-testing in Ruby. There is a situation that I don't know if is good enough or if I am doing the wrong abstraction. I have two classes: ...
3
votes
0answers
67 views

Ruby on Rails text editor

I'm currently building a text editor using contenteditable and RoR back end. As the editor is WYSIWYG and trying to follow DRY, I used only one file to 3 actions: Show, Edit and New. Edit and new ...
7
votes
4answers
294 views

Ruby-ize for loop - counting all the n-digit numbers that contain the digit 5 anywhere

I wrote this a while back when my fiance was taking a Number Theory class. I wrote about it here and it recently came back to my attention. Anytime I write a for ...
4
votes
3answers
91 views

Search for User by first and/or last name, efficiently

I am refactoring a user search that just feels dirty. (Users#search) I need to allow a blank param to search on partial or only a first or last, but don't want to return all the records in the ...
1
vote
1answer
50 views

Is my code clean enough and standard when processing Ruby on Rails requests using User's time zone?

I have an application in Ruby on Rails (3.2) and I want all the requests to take into account the currently logged in user's time zone. Also, I want to have a helper that will let me display date ...
4
votes
1answer
94 views

Merging with different modules

We have an action merge for two projects. In the projects we have different modules like Feed, Files, Post etc.... ...
7
votes
2answers
109 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 ...
1
vote
1answer
23 views

Move update_attributes into class and check for non-nil params to update only

There are a number of things wrong with the code here: ...
4
votes
1answer
61 views

Small football table builder in Ruby

Please review this small program I wrote to create a World Cup Group Table. You feed the program match info, and it builds a table based on that info. ...
5
votes
2answers
47 views

Refactor .each where each is redirected into a hash

What would be the best way to refactor this : ...
2
votes
1answer
32 views

Avoid calling nested method two times

For a given file name path, I need to get the folder one level before it. This can be accomplished in ruby with the following code: ...
2
votes
2answers
28 views

Refactor mass assigning from a hash

Here is the piece of my controller action that takes a session[:auth] hash and then assigns the values to the ActiveRecord object represented by ...
4
votes
0answers
97 views

Hacking Ruby Hash: Fastest #to_struct method

I am trying to make the fastest #to_struct method in Ruby's Hash. I am including a use case and benchmark so you can run and see if you have really improved the ...
2
votes
1answer
54 views

Ruby on Rails: refactor big search method

I have big search method in my model that corresponds to search a proper Car. It looks like this: ...
4
votes
1answer
100 views

Optimize a zscore algorithm

I wrote a zscore algorithm in Ruby that runs fine, but is incredibly slow when I have 8000+ entries to score. Can anyone help me figure out a way to improve my code, please? ...
1
vote
1answer
49 views

Better way for accumulating a value than using inject/reduce with conditional operator?

When there is a situation where I want to accumulate a value I see myself using inject/reduce with a conditional statement. E.g., when I want to add 1 to a value each time an element in a list has a ...
1
vote
0answers
22 views

Displaying blog posts from non-SSL site in SSL site

The Issue I added SSL to a previously static and non-SSL website because some new features will require it. I'm using rails 4.0.5, ruby 1.9.3, and the site is deployed on heroku. [it's at www dot ...
3
votes
2answers
42 views
5
votes
1answer
57 views

Reverse-engineering with Filepicker API

I have this script to pull data out of the Filepicker API internal. It's mostly reverse-engineering and the code seems to be ugly to me. How can this be improved? ...
3
votes
3answers
68 views

Speed up counting sort algorithm in Ruby

I'm attempting this simple HackerRank counting sort problem but testcase #3, which has 100,000 test cases, is timing out. Is there something particularly inefficient about this code? ...
1
vote
3answers
80 views

Avoid passing variable from class to class

For context, I have a SourceControlSystem factory class that detects if a user is using Git, SVN, or another source control system and returns an object to interact ...
1
vote
0answers
42 views

scraping and saving using Arrays or Objects

I'm using Anemone to Spider a website, I am then using a set of rules specific to that website, to find certain parameters. I feel like it's simple enough, but any attempt I make to save the ...
2
votes
0answers
35 views

Attempting a retry of a read from socket

I'm working on a project in Ruby right now that utilizes EventMachine for it's networking library and Wisper for passing messages around the application. However, I've come into something I think ...
6
votes
2answers
51 views

Refactor an XML to JSON parser class

I used Nokogiri and a piece of ActiveSupport to parse an xml file from a given URL, format the data properly and return a JSON string. The script works as expected, so I'm only wondering if there are ...
5
votes
2answers
120 views

Sorting an array in alphabetical order

I'm looking to get some feedback on this program I wrote - ways I could make it simpler or best practices methods. Chapter 7: Let's write a program which asks us to type in as many words as we ...
6
votes
2answers
161 views

Correct use of procs in Ruby

I wrote a Ruby gem to analyse strings for word length, word density, and a few more hand methods... The Counter class accepts a filter (String). The class will ...
1
vote
2answers
26 views
5
votes
1answer
55 views

httpclient: Let OpenSSL decide which TLS protocol version is used by default

I use Gem in a Box, a Ruby project that allows to create personal self-hosted gem repsitories. Gem in a Box uses httpclient to connect to the gem repository. After ...
0
votes
3answers
94 views

Which syntax is preferred to create a Hash in Ruby on Rails?

I am writing some code in Ruby on Rails to Create an object. I am using Ruby 2.0 and Rails 4.0.3 in my Application. I have a Model called: ...
5
votes
2answers
164 views

Shortening / refactoring code for checking for a win in TicTacToe

It looks like it should but I can't see how. I have my methods <= 5 lines but that's as far as I got: ...
1
vote
1answer
61 views

Key and value mapping from one object to another

I've been trying to figure out a clean way of managing mappings between two objects. In the case of this example, it's two hashes. This spec should illustrate the problem at hand: ...
1
vote
1answer
52 views

Search a value across 2 array

I want to find the corresponding hash in an array from a string that contains a criterion defined in a hash of the array. I do something like that : ...
2
votes
2answers
76 views

Rock, Paper, Scissors game

I'm very new to Ruby and am building my first game. I have made this game, and to be honest I did it this way because I was lazy to type so much. My friend told me that the correct way was to do this ...
1
vote
1answer
28 views

Implementation on AMQP in Ruby

I need comments on the below code: ...
1
vote
0answers
60 views

Is this Ruby freeze too wordy?

I've been looking to improve performance in certain key portions of my app. I've started by using Ruby 2.1.1 frozen strings to reduce memory allocation work and speed up performance. Simple ...