Ruby is a multi-platform open-source dynamic object-oriented interpreted language created by Yukihiro Matsumoto (Matz) in 1993.
2
votes
3answers
81 views
Refactoring a case statement in ruby [on hold]
I have the following case statement where I'm using ranges to find a value. This works but it seems like it could be better. Any suggestions on a more "ruby" way of doing this?
...
4
votes
2answers
165 views
Multiple attempts to find the best icon
I have a series if statements where I am trying to find the highest resolution file in an set of files. Is there a way that I can refactor this code to be shorter and or cleaner?
...
4
votes
1answer
32 views
Rails configuration variants for production / development environments
How can duplication be removed from this?
...
-4
votes
0answers
31 views
How to express `not 0 neither nil` in ruby [on hold]
I want to check if foo is not 0 neither nil.
What come to my mind are these two expression.
...
0
votes
0answers
27 views
Is it bad practice to fake a pass method in ruby? [on hold]
Ruby doesn't have a pass method to 'do nothing' the way Python does - if I want a ternary statement to do something on true, but nothing on false (as in the code below) is it bad practice in Ruby to ...
2
votes
1answer
30 views
Ruby Soduku X-wing solution
I have written a Sudoku solver, for the euler problem and also packaged it into a ruby gem. In my solution strategies I do a lot of iteration (double/triple nested loops, I am coming from Java/C). ...
3
votes
1answer
44 views
Code Quality Catch-22 — Duplication vs Complexity
I've started using Code Climate to assess some of my code quality and ran into a situation that I can't seem to find a good solution for. In short, in trying to solve some code duplication that ...
4
votes
1answer
48 views
Strategy to reduce duplicate code in many similar modules
The Situation
I have created some code in the form of modules that each represent a medical questionnaire (I'm calling them Catalogs). Each different questionnaire ...
3
votes
3answers
66 views
2
votes
2answers
29 views
Product matcher refactoring regarding scopes and arrays
I know I have seen this before and I can't remember how to fix it or find where I saw how to fix it:
...
1
vote
1answer
19 views
The block should return the user's current_active_role
def current_active_role
user_roles.each do |r|
if r.is_active_role
return r
end
end
return nil
end
The block above returns ...
3
votes
1answer
26 views
Refactoring a simple Ruby CLI program
I tried to help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can ...
2
votes
1answer
27 views
Ruby program to simulate a game of Narcotic Solitaire
In the game of Narcotic Solitaire, played with a standard 52-card deck, the player deals a row of four cards onto the table, from left to right. If all four cards are of the same value, they are ...
0
votes
1answer
26 views
Refactor Net::SFTP Upload
I have a method to upload a file using the Net::SFTP gem. My method looks like this:
...
1
vote
1answer
57 views
An easier way to test a valid username
I have the following requirement for valid usernames:
Only alphanumeric characters and -
Must not start with a -
I wrote this regex (on Rubular):
...
3
votes
1answer
49 views
Ruby selenium script waiting for an element to disappear
I'm a Java developer, I'm new to Ruby and I'm worried that I'm forcing or not-so-well using the goodness of the Ruby syntax.
What do you think about the Exception catching and how to print it in ...
4
votes
1answer
45 views
RSpec test for pagination
This is a Rspec test for pagination in Rails project. I'm not sure if I should write the test in spec/requests or ...
3
votes
1answer
48 views
Reading a file in chunks
I currently have the following class that takes a custom file object as an argument and makes a copy of the file locally.
...
1
vote
1answer
50 views
Making an HTTPS request more readable
I think the snippet is too nested having too many blocks. It needs to be refactored to make the logic more readable.
The try exception is the first level block
...
3
votes
4answers
81 views
Tic Tac Toe in Ruby
This 2-player tic-tac-toe game is the first thing I've really written from scratch in Ruby, without the guidance of a tutorial. I'm interested in knowing what could be improved upon to make the code ...
3
votes
2answers
61 views
Ruby hashes of status counts
I have a method that takes a model object, reads through its children and returns a hash of status counts. It should only return a count on a status if one exists.
This method works, but I was ...
2
votes
1answer
31 views
Displaying shows with videos
My method takes a long time to respond, so I'd like to make this method more efficient. I'd also like this method made with joins.
...
4
votes
2answers
52 views
Convert string array to object with true/false flags
Currently a filter parameter of a GET request is used to designate items' categories that will be requested from database and displayed.
The parameter contains ...
4
votes
3answers
91 views
Find the last element of a list
Find the last element of a list from codewars.com
Example:
last( [1,2,3,4] ) # => 4
last( "xyz" ) # => z
last( 1,2,3,4 ) # => 4
I completed this ...
8
votes
2answers
292 views
FizzBuzz from a casual rubyist
As a casual Rubyist I am mainly interested, how ideomatic my solution is.
...
5
votes
6answers
163 views
Project Euler problem 4 in Ruby
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two ...
4
votes
2answers
87 views
Writing successive function calls
I have a Ruby function which generates and saves a report. I'm looking for a Clean Code way of writing this:
...
8
votes
4answers
259 views
Count cars passing in opposite directions
The problem comes from codility, whose coding problems I'm starting to enjoy as their evaluation criteria really looks at runtime.
Task description
A non-empty zero-indexed array ...
4
votes
4answers
59 views
Validating a Collection of IPv4s
I have a method within a class that validates all proxy addresses are valid on initialization. I've tried to refactor this a bit, but this seems to be the best I can do. Any suggestions and/or tips as ...
9
votes
3answers
110 views
Making kexec reboots less painful
kexec is a way for a Linux kernel to directly boot another Linux kernel without going through the usual BIOS startup sequence, which can take several minutes on enterprise servers. The big problem ...
7
votes
1answer
59 views
Controller action to process orders and payments
I'm trying to reduce the if statements and simplify this create action.
...
6
votes
3answers
298 views
Towers of Hanoi
I am just learning how to code in Ruby now with no prior experience. This is 3 towers of Hanoi where the user selects where to choose from and where to go with each disc, and not to have a bigger disc ...
2
votes
3answers
68 views
Tell, Don't Ask when dealing with displaying model attributes or a null replacement
I have the following model:
...
0
votes
1answer
134 views
Project Euler - Problem #11 - Ruby
As a beginning Ruby programmer I implemented a solution for Project Euler, Problem #11. (The problem is described in the comment below.) I'll be grateful for any suggestions for improvement ...
2
votes
1answer
55 views
DRY-ing up some rspec
I have an rspec spec test that has two sets of the same tests (from 24 Pull Requests). I thought I'd refactor the spec whilst I fixed something else.
Normally I just do a basic ...
4
votes
2answers
49 views
Rendering a selection box for 50 states
I was creating a Rails form where users have to enter their state. I ended up creating a select tag which is really, really ugly.
I'd like to think there's a better way of writing this.
...
0
votes
2answers
66 views
Factory Girl in Rails
I have a FactoryGirl page that generates same data but in two different languages. The variable names are the same. How do I write it in the smartest way possible without having to write a huge bunch ...
2
votes
3answers
99 views
Refactoring RSpec/Capybara tests
Is there a better way of representing this RSpec code on Rails using Capybara?
There are three scenarios only for when the sign up validations fail so is there a better way of representing them ...
2
votes
3answers
72 views
URL resolver for Users, Lessons, and Series
My Resolver.resolve class returns a hash of objects and I would like to return a specific object if it exists. Is there a more concise way to write this?
...
3
votes
2answers
67 views
Reservation validation
I got a Reservation model that has reservation_start and reservation_end.
Then I have the ...
2
votes
2answers
60 views
CSV File Parser in Ruby - Attempt No. 2
The following is my second attempt at a basic CSV parser in Ruby. I've addressed suggestions that I've got for my previous version here.
I have omitted all test cases - the code listing would be too ...
1
vote
1answer
55 views
Reduce memory use for a property geolocator
I have to run a script against 40 million objects in my database:
I wrote the script and I want 10 instance of it so I process my objects faster.
The goal is to find all the neighborhood for each ...
0
votes
1answer
77 views
Avoiding Duplicates in a Ruby on Rails Factory Girl Factory with Fake
I have a Factory Girl factory that needs to generate a unique name using Faker. Unfortunately, Factory Girl generates duplicates relatively frequently, which causes intermittent test errors. I ...
4
votes
2answers
106 views
Ruby object oriented Snakes and Ladders implementation
I'm not a beginner to programming, but I am to programming in OOP (effectively at least). So to learn better I wrote an object oriented game of Snakes and Ladders. For background, see this question.
...
3
votes
2answers
90 views
Multifunctional Monty Hall Simulator
Based on this question on math.SE regarding probabilities in variations on the Monty Hall problem, I cobbled up a simulator in Ruby to give myself an introduction to the language.
Since this is my ...
0
votes
2answers
109 views
Multiples of 3 and 5
Project Euler problem #1:
If we list all the natural numbers below 10 that are multiples of 3 or
5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples ...
-1
votes
1answer
62 views
Feeder for returning an array of items rated by users
Feeder is in charge of returning an array of items rated by users (feed). If there is a watching user (...
3
votes
1answer
155 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
2answers
99 views
Snakes and Ladders random world generator second implementation
The following is an implementation of a random world generator for the classic Snakes and Ladders game. This is a follow up to this question, where I reviewed my own original implementation. I am ...
4
votes
1answer
81 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 ...