Ruby is a multi-platform open-source dynamic object-oriented interpreted language created by Yukihiro Matsumoto (Matz) in 1993.
1
vote
1answer
35 views
2
votes
0answers
37 views
PDF-to-JSON converter
I've created some methods to help me convert PDF to text and then text to a JSON object. I've never done this before and I'm using this exercise as a way to improve my knowledge of Ruby.
The ...
3
votes
1answer
29 views
Different factorial algorithms
I'm new to Ruby and as an exercise I implemented different factorial algorithms. Other rules are: raise an ArgumentError exception if n < 0 or if n is not an integer.
I'm interested in whatever ...
0
votes
0answers
12 views
What is a best approach to match an array in RSpec? [on hold]
I was struck with multiple paths to write a test in rspec of controllers.
But do not know which of these is the best, I will outline what I think the approach and would love for you to tell which ...
1
vote
0answers
23 views
Improving JavaScript processing of Ruby Regex
I have a basic webapp that basically serves the same purpose as Rubular.com, but for gsub.
It runs some simple JavaScript, which POST's to a Sinatra app, which then updates page with the results.
...
10
votes
4answers
125 views
1
vote
1answer
34 views
String PathParser
I'm trying to decide if I should put time into refactoring this tiny class. PathParser only uses string locally and every other method is used by an outside class. ...
2
votes
1answer
37 views
Caesar Cipher implementation - Odin Project
I am going through the Odin Project Ruby section, and just finished implementing a Caesar cipher interpretation. Should I use classes, or more than one method to distribute the flow? Is there really ...
2
votes
1answer
40 views
Binary convert to string in Ruby
This was a challenge for reddit #202 Easy /u/learnprogramming ...I wish that someone reviews my code and let me know your opinion about my way of thinking beacause I am a total beginner in Ruby:
...
3
votes
2answers
105 views
Optimizing Multiplication Table
I have a class that takes an array of integers and produces a multiplication table.
...
5
votes
1answer
62 views
Computing overall averages in my web application
I'm a senior Comp. Sci. major working on a senior design project for our faculty. The name of this project is "Gradebook", and it is responsible for allowing instructors to record grades for students ...
4
votes
2answers
204 views
Simple calculator using eval
The following code is for a calculator made in ruby, I find that this way saves much time than having to build this calculator from scratch, especially that I want it to support BEMDAS operations. ...
3
votes
2answers
37 views
4
votes
3answers
165 views
Parsing a string of the form “key1=value1;key2=value2;” into a Hash
I need to parse the following input string into a hash table with the following format:
Input:
'1001=23;1001B=5;1002=0;1003=5;'
Output:
...
4
votes
1answer
47 views
Readable Caesar cipher
I was trying to refactor the following code for Caesar cipher, but it feels overly complicated at the end of the refactoring. Could someone else take a look at it and let me know if I am just ...
4
votes
1answer
68 views
Project Euler problem 12 in Ruby
I've been trying to optimize this while making it readable. Thoughts?
The sequence of triangle numbers is generated by adding the natural
numbers. So the 7th triangle number would be 1 + 2 + 3 ...
3
votes
2answers
50 views
Titleize words in a sentence but with some conditions
Below is the code I have written to capitalize all the words of a sentence except if
The words belong to the littleWords list.
The word would be capitalized if it's the first word of the sentence ...
3
votes
1answer
52 views
Probability ordering by seller's tariff
I have an instance method (update_priority); it calculates the position of an element, depending on the tariff of its seller.
If the seller is of a level3 tariff, ...
2
votes
3answers
88 views
Summing data from two arrays, grouped and sorted by date
I have multiple multidimensional arrays that each have the same structure with different lengths.
...
0
votes
2answers
32 views
Testing a simple guard clause in isolation
I’m using decorator objects in a Rails app so that I don’t have to do nil? checks in views. Everything is working nicely and it’s easy to test, but I’m suspicious ...
15
votes
2answers
1k views
99 bottles of beer on the wall
I'm super new to this so please be nice. I tried solving Chris Pine's challenge to print the entire lyrics to 99 bottles of beer on the wall. This seems to work, but is there a better/more efficient ...
1
vote
1answer
42 views
A simple Ruby EmailAddress class
I wrote this short, plain Ruby lib to handle email address validation inside and outside of Rails applications, and I would like to know what you think.
...
2
votes
3answers
48 views
Similar methods to update today's sales, revenue, and profit
Please help me to refactor. I have two models, conversion & statistic.
Methods ...
2
votes
1answer
71 views
Mathematical expression evaluator and equation solver
I'm trying to implement a mathematical expression evaluator and equation solver, and based on extensive online research and my own experimentation have come to the conclusion that the best way of ...
1
vote
1answer
35 views
Rails integration testing: Should we use strings or named routes in http requests?
When integration testing Rails applications HTTP request helpers can take a string or a named route as the first argument.
I find myself writing:
...
2
votes
3answers
113 views
Refactoring a case statement in ruby [closed]
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?
...
3
votes
2answers
205 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
57 views
Rails configuration variants for production / development environments
How can duplication be removed from this?
...
1
vote
1answer
54 views
Faking a pass method when building an array
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
42 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
51 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
57 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
82 views
2
votes
2answers
34 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
22 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
28 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
29 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
37 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
59 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
80 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
60 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
59 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
51 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
107 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
68 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
34 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
59 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
100 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
297 views
FizzBuzz from a casual rubyist
As a casual Rubyist I am mainly interested, how ideomatic my solution is.
...
5
votes
6answers
181 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 ...