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
0answers
6 views

Find and select image files from webpage

For some reason, I feel like this is a bit messy and could be cleaner. Any suggestions? I'm selecting any image files ending in .png or ...
0
votes
0answers
14 views

Simplifying Rails routes [on hold]

I have next routes: resources :books do get 'page/create_page' => 'pages#create_page' get 'page/new_page' => 'pages#create_page' end That compiles ...
3
votes
1answer
20 views

Optimize mass import of XML to SQLServer in Ruby

I have the following Ruby code that's designed to update item, price and stock data for items in a MSSQL database. It's running on a Ruby 1.8.6/Rails 1.2.3 installation, in its own controller (for ...
0
votes
0answers
29 views

Nested if-else with assignment [on hold]

This is in Ruby. This is the best I could get. How can I refactor this? if method == 'xxx' a = x.split('|').first if x a ||= y else a = x || y end
4
votes
2answers
35 views

Generating sequence that uses the previous outcome for the current

I do not like to use while loops in Ruby. I was wondering how I can generate a "squared sequence" (e.g., squares the first input, then squares the outcome, etc.) in ...
5
votes
2answers
674 views

Reducing this code to the minimum possible

I have an API with the following code ...
1
vote
0answers
11 views

Determining encoding for a file in Ruby [migrated]

I have come up with a method to determine encoding (or at least a guess at it) for a file that I pass in: ...
2
votes
3answers
39 views

Code to evaluate a dotted quad IP address has clumsy use of inject/fold - can I match the pattern in Ruby?

I wrote this to consume valid IPv4 addresses in dotted-quad decimal form. ...
7
votes
1answer
40 views

Command line flashcard game

I've built a simple command line flashcard game for learning Korean. I'm a beginner programmer, so I just wanted to make sure I'm following best practices, especially pertaining to OOP principles. ...
5
votes
2answers
32 views

Convert cardinal abbreviations into full cardinal direction

I'm still learning Ruby and I made the following function to convert "N" or "SE" into ...
4
votes
1answer
46 views

Is this a good Ruby implementation of Prime Factorization?

I'm doing some practice problems on Khan Academy. The current one is Prime factorization. I came up with this: ...
3
votes
2answers
95 views

Capitalize all words in sentence string in Ruby

I have created the following code: def LetterCapitalize(str) str = str.split(" ").each {|word| word.capitalize!} str = str.join(" ") return str end This ...
13
votes
4answers
973 views

FizzBuzz in Ruby

I have this implementation of the FizzBuzz challenge in Ruby: ...
1
vote
0answers
17 views

What kind of exception to ask for out of range arguments? [migrated]

What type of exception should I throw? I have a console class which describes rectangle of cells which a user can index by passing in a coordinate: ...
10
votes
3answers
252 views

Git pre-commit hook to check that changes to certain files only happen on the master branch

As a beginner in Ruby, I am trying to optimize this script that is a client side pre-commit hook for git. Was hoping I could get a review to ensure I am following all ruby idioms, and to ensure I ...
13
votes
2answers
115 views

Nokogiri crawler

The following code works but is a mess. But being totally new to Ruby I have had big problems trying to refactor it into something resembling clean OOP code. Could you help with this and explain what ...
8
votes
5answers
248 views

Convert total minutes into “Hours:minute:seconds” for marathon data

The point of the script below is to read in the 10th column which is the total number of minutes a runner took to finish the marathon and convert it into form of "hours:minutes:seconds". Is there a ...
6
votes
3answers
96 views

Generate random 10% of file to be used in testing with Ruby

I'm new to Ruby, but not to programming. I just need a simple script that, given a text file, will pull out around 10% of the lines at random. Below is what I came up with based upon a Python script ...
3
votes
2answers
130 views

Building a list - why is this code inefficient?

I'm attempting this code challenge. Here's my code modified to handle one simple example test case: ...
6
votes
2answers
73 views

Project Euler code evaluation - digit fifth powers

This is for Project Euler #30: Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: \$1634 = 1^4 + 6^4 + 3^4 + 4^4\$ \$8208 = 8^4 + ...
4
votes
1answer
72 views

Better way of checking if the current user already like a post

I have three models which look like this: ...
1
vote
1answer
38 views

Cleaning up a class that contains the object it represents [closed]

I've recently started writing a tic-tac-toe game (following the Odin project) and am trying to write a class to hold the board game. What I'm not sure about, is that the board class holds all the ...
7
votes
1answer
144 views

Less-repetitive code for document-analyzer

I've refactored my code such that every function has only one responsibility. Now I'd like like to work on making it DRY. I'm noticing a lot of duplication in the ...
4
votes
1answer
80 views

How could this “complex method” for codeclimate be refactored?

I'm trying to figure out how to refactor some code based on what codeclimate is telling me. So far it seems that any method that is longer than 5 lines or has an ...
1
vote
0answers
54 views

Variable assign expression with multiple expressions

I have three types of variable assign expression with multiple expressions. It looks ugly, but I'm not sure how to make it more readable. Type 1 ...
0
votes
1answer
50 views

Better practice to find the max/min element in a loop

Is this the most elegant way to avoid declaring additional variables outside the following_triggers loop? ...
11
votes
3answers
908 views

The Love-Letter Mystery

Problem Statement James got hold of a love letter that his friend Harry has written for his girlfriend. Being the prankster that James is, he decides to meddle with it. He changes all the ...
1
vote
0answers
43 views

Written worker using sidekiq for activerecord class

I have two model classes as follows: ...
2
votes
1answer
54 views

Ruby Bot application [closed]

I just want to know if this looks good. ...
1
vote
1answer
51 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
11 views

Memcache Keys Management Class

I have written below class to manage Memcache keys. My Memcache keys structure are like: ...
6
votes
2answers
64 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
70 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
3answers
71 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 ...
3
votes
4answers
79 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
33 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
53 views

Replace outside comma with newline

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

How would you refactor this case statement?

I've got this code in my ApplicationHelper file: ...
4
votes
0answers
63 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
32 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
38 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
73 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 ...
3
votes
1answer
73 views
+50

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
47 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
96 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
313 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
110 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
53 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
101 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
113 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 ...