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
1answer
31 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 ...
2
votes
0answers
29 views

Binary Search Tree in Ruby

Binary Search Tree, with preorder traverse. What other methods should I add? How can I improve it? ...
3
votes
1answer
50 views

Bloom filter implementation using a BitArray

I am following the Wikipedia definition of the Bloom filter. My implementation uses the BitArray I created in Bit Array in Ruby using integer as a storage. An ...
3
votes
1answer
60 views

Bit Array in Ruby using integer as a storage

Ruby's Fixnum & Bignum can hold very large integers and automatically handle overflow. I decided to implement BitArray using an integer as storage. Please let me know what you think about code and ...
1
vote
0answers
20 views

Multiset implementation in Ruby -Take 2

This is a follow up to question. I fixed the issues mentioned in the answer as far as my understanding. The union and intersection now return new object instances with new implementation. I also wrote ...
2
votes
1answer
34 views

Multiset implementation in Ruby

I am trying to implement the wikipedia definition of a MultiSet. Need feedback on implementation. Also I am not sure how to implement cartesian product. ...
1
vote
1answer
33 views

Orange Tree simulator

I'm practicing SOLID principles and the concept of making a clear distinction between an object's private and public interfaces. ...
6
votes
1answer
68 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 ...
-1
votes
0answers
34 views

Design battle - Best approach for one line if else condition loop [closed]

Approach 1: formattedTitle: (-> if @get('title') "City - #{@get('title')}" else "City" ).property('title') Approached 2: ...
-2
votes
1answer
47 views

SQL table: store “status” as integer vs as string [closed]

I've been around a bunch of projects where statuses are stored in the db as a integer, then mapped in the model back to a human readable string: ...
7
votes
1answer
82 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 ...
1
vote
0answers
33 views

Testing after_save hooks in rails 4.2 with MiniTest

I've recently started working on a new application in rails 4.2.0-beta2. I've been using this as an opportunity to learn more about MiniTest, with a stretch goal of being as strict with myself with ...
1
vote
1answer
26 views

DRY up ivar assignment in Rails new and create controller actions

When creating a new model in Rails, I need to pass a bunch of other models into the view so I can define the correct associations. All I’m really doing here is querying the persistence layer for ...
3
votes
1answer
48 views

Circular Buffer implementation in Ruby

Does the implementation look correct? Did I miss something major/minor? ...
6
votes
2answers
61 views

How to avoid mounting SQL by concatenating strings?

I found myself mounting a query by concatenating strings. This just seems wrong. Any ideas of how to avoid this kind of situation? I'm using Rails 4, and I don't see how can ...
1
vote
2answers
48 views

SSH Class with a method for downloading via SCP

I am looking for a code review on this class. I found myself writing this logic a lot, so trying to save myself some time. ...
1
vote
1answer
23 views

Array to a hash, ruby code reduction

I have an array of thing objects, each of which has an array of categories. I'd like to build a category hash with a category ID for a key and an array of things ...
6
votes
2answers
62 views

Leap year functionality in Ruby and JavaScript

I did a line-by-line translation and am wondering if the JavaScript code looks idiomatic. Original Ruby code: ...
3
votes
2answers
30 views

Initialise simple_form object inline

Using Rails 4 and a simple form, I'm rendering a couple of forms outside of their native controllers. Rather than scattering initialisers through my controllers, I wondered if it is cleaner to do the ...
2
votes
1answer
78 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 ...
4
votes
1answer
80 views

CodeEval Sequence Transformation

I've been working on this challenge for a week: There are two sequences. The first sequence consists of digits "0" and "1", the second one consists of letters "A" and "B". The challenge is to ...
2
votes
1answer
112 views

Chat console using Ruby and Rust

One of the exercises I like to program when learning a new language is a chat client for the console. I've programmed it in many languages (Perl, Python, C, C++, JavaScript, ...). One of the versions ...
2
votes
2answers
47 views

Get ruby Hash#each to return a built hash

I'm golfing some code while waiting for a coworker, and I shortened a function to this: ...
12
votes
1answer
91 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 ...
7
votes
3answers
70 views

Calendar Print Method

I'm currently learning Ruby and need help in editing code to be more idiomatic. I have the method below I could use some pointers on how to make more "Ruby" :-) ...
0
votes
2answers
57 views

Make multiple conditions in if expression more readable

My logic has to be written in this way, but I think the if expression is too long to read. How can I make it more readable? ...
1
vote
1answer
42 views

View for displaying nounal and verbal pages

I've got this code in my View that just list two type of links. Here's an example output: Nounal Pages cleaners/house-cleaners Verbal Pages cleaning/house-cleaning Here's the view code. How ...
1
vote
1answer
62 views

How do I bind a symbol in a conditional in Clojure? [closed]

In Ruby (on Rails) I would do this in a controller action to provide authentication: ...
3
votes
1answer
48 views

Searching for something at a location

I'm using Searchkick in a situation where a user might write the location they are searching for, or the thing they are searching for, or both. I've been working on the below code for most of the ...
1
vote
1answer
52 views

Ruby on Rails Method ActiveRecord Query Optimizations

So I have three methods and I'm not sure how to optimize them. I will be working on this and updating this post while I do but basically running these three methods is central to some parts of my ...
4
votes
1answer
37 views

Writing a safe class method in terms of a dangerous one

I commonly need to trim characters from the end of a string (when building SQL queries, I have trailing commas, brackets, even words sometimes), so I wrote the following: ...
0
votes
2answers
104 views

Fastest way to find maximum deviation

I acknowledge that this exact question was asked here. I was working on the same problem from the same website. I had the same question and consulted the above as a reference, however with respect ...
1
vote
1answer
66 views

Creating a Custom Set Data Structure in Ruby

I wrote a set DS with some useful functions. Not sure if it is a good implementation and if there are other essential functions that a set should support. ...
3
votes
1answer
65 views

Ruby Repository Pattern

I am trying to teach myself about repository pattern in ruby. Could you please review my code. adapter.rb ...
1
vote
1answer
37 views

Speed up anagram method in Ruby

I'm working on a project to find anagrams of words. My goal is to figure out the longest anagrams out there. I took a look at my code and it works but is woefully inefficient. I have two arrays, each ...
5
votes
3answers
64 views

Structuring code that shells out to an external script

This code that shells out to an external script could use some input in order to read smoother, I think. Praise and critique are welcome. ...
5
votes
1answer
74 views

Binary Search in Ruby

I want to write a search that raises an error if the list supplied is not sorted. ...
0
votes
1answer
43 views

Improving Watir::Browser for my needs

I want to: use Watir::Browser methods without browser. instance prefix expand abilities of ...
1
vote
2answers
33 views

Removing duplication in RSpec

I’m still relatively new to the TDD scene. I’m writing a Rails app, and some duplication immediately sticks out at me in my first model spec. How else can I approach this? ...
5
votes
2answers
92 views

Rails controller method that conditionally filters results

This code for my blog checks to see if tags are in the params hash. If they are, then only posts that are tagged will be paginated. Otherwise, all of the posts are paginated. ...
4
votes
1answer
40 views

Calculation in Concern module using Rails

I wrote the following Concern module. Is it good practice to perform all the calculations in the included scope? How can it be ...
7
votes
1answer
469 views

Breaking a chess coordinate string into 2D coordinates

Given a chess coordinate as a string (e.g. "a1") I'd like to transform it into a 2-D array (so, for "a1" I'd like to get [1,1]). Here's what I came up with: ...
3
votes
5answers
99 views

All Possible Products

I'm trying to find all possible product of two 3-digit numbers. When I work with small ranges, I'm able to get an output almost instantly but when the ranges are big, it seems to take really long ...
1
vote
5answers
58 views

Refactor auto-incrementing function in Ruby on Rails

I have a Rails app where we generate calls. Each call has an incident_number which is a unique number based off the following format: 14-00001 (year in 2 digit followed by a dash then a 5 digit ...
2
votes
2answers
70 views
2
votes
1answer
37 views

Greed in Ruby Koans

I've finished the greed problem in Ruby Koans after much confusion. This is my first programming language and I have been doing fine, but then this problem really tripped me up for some reason, ...
1
vote
4answers
18 views

Issue in Ruby Programming Style

I am new to Ruby on Rails. Can some one please help me with this question? How would you modify the following to be consistent with Ruby's style? ...
2
votes
2answers
75 views

Ruby Mod 11 implementation

I wrote this Ruby Mod 11 (perhaps it's a bit generous to call it that) implementation to validate Brazilian CPF documents, which use a Mod 11 algorithm. CPF format is a 9 digit number followed by two ...
-1
votes
2answers
149 views

A platform-independent implementation of “which” in Ruby

I like to know if there's anything that I may have missed in this implementation. The method tries to provide the absolute path of the binary or script which is likely to execute based on the provided ...
3
votes
0answers
85 views

Heterogenous tree in the application domain: How do I represent them?

The Domain I have three types of items in my domain: ItemA, ItemB, ItemC. (I can't use their real names.) ItemA has one attribute: thing_id. ItemB has 6 attributes: thing_id, name, description, ...