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
2answers
16 views

Project Euler #1 in Ruby with duration

I have done #1 of Project Euler's in Ruby. Using two different approaches. One uses set, another uses reduce. ...
2
votes
0answers
17 views

Song search app with dynamic tables

I decided to make a Ruby app to search for songs, it uses the tinysong API. Things got really cryptic and weird in the view, I managed to get dynamic tables that adjust to data length, but I feel like ...
0
votes
1answer
24 views

Ruby singleton for logging

I currently have a logging setup that looks like this: ...
2
votes
0answers
43 views
+50

Fetching photos and tweets related to selected publications

1) Postgresql 2) User has_many :reports 3) Report belongs_to :user 3) Report belongs_to :publication 4) Publication has_many :reports 4) Publication scope :photos, -> ...
5
votes
1answer
24 views

Putting numbers into words

I have some embarrassingly long code which puts into words any number up into the trillions. As a newbie, and understanding that shorter, non-repetitive code is best, I am looking for suggestions on ...
2
votes
3answers
43 views

Controller actions permisson specs

I'm just starting with rails and testing, and not sure what's good way to dry code like this. ...
1
vote
0answers
24 views

Rspec test reuse code for before_filter and method

Consider following example (controller): ...
1
vote
0answers
25 views

Asynchronous execution

I needed several classes with methods performing network requests which should be executed asynchronously (with callbacks). To get rid of repetition, I added a mixin and a helper class: ...
3
votes
2answers
77 views

Improving the efficiency of my FizzBuzz algorithm [closed]

I worked on an exercise from codewars, which is a variation of the popular fizzbuzz game. (If the link doesn't work, you may need to reload the page.) In this variation, I'm supposed to find the sum ...
4
votes
2answers
57 views
0
votes
0answers
21 views

N+1 query on Ruby on Rails

I have a has_many through relationship between my cities and travels that looks like this: ...
2
votes
0answers
28 views

Sports statistics controller

Is there too much logic in this controller (should I migrate them to the model)? How else can it be refactored? ...
3
votes
1answer
47 views

Combining CSVs using ruby to match headers

I am trying to write a ruby script that will take all of the CSVs in a given directory and map their headers out so that duplicate columns will match up and columns unique to a file will have their ...
0
votes
0answers
7 views

Verbose parent/child matcher errors for Rspec [migrated]

Given the following code, when I get a failure, I would like to see both the parent and child diff's shown. Currently, if I have a mismatch at the children level, I only get feedback that my parent ...
5
votes
1answer
44 views

Interface to a CSV dinosaur database

I have just finished with the first Ruby exercise on Level Up Rails, and wanted to get an idea on how I can refactor the code. You can find the original exercise on github - including the ...
-1
votes
0answers
16 views

PostsController#search function

This function is the heaviest function in the entire site and there are a lot of queries to run just to load the view page. Please work towards reducing the number of database queries. ...
1
vote
0answers
33 views

Using Middleman efficiently

My site is generated by Middleman. I know I could be using HAML, and Sass, and other optimizations are possible, but what I'm curious about at this stage is DRYing up code in my custom helpers, and ...
1
vote
1answer
52 views

Ruby webserver app

I am building a web app in Ruby but without Rails. So far I just have a very basic web server. What improvements can I make to it? ...
3
votes
2answers
75 views

Solution to Max Range Sum challenge on CodeEval

The challenge in CodeEval is to take a number of days and iterate over the gains and losses and determine which lengths will yield the highest possible profit. I'm wondering if I could write this any ...
2
votes
0answers
42 views

Extracting dynamic behaviors of state machines to modules

This is my initial class. (I am not trying to reinvent state-flows again, just practicing) As you can see straight forward, it dynamically generates methods like .recommend,.recommend!, ...
1
vote
0answers
29 views

Create a list of actors based on their movies [closed]

I want to optimize this code for speed. I think there is more faster way. ...
2
votes
4answers
61 views

Return the opposite of two known strings given one

This is probably silly, but I feel like there should be a much more elegant way to do this simple thing. I have two known strings, whichever one is passed in in the parameter I want to return the ...
1
vote
1answer
52 views
2
votes
0answers
65 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
35 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 ...
1
vote
0answers
28 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
152 views

Lottery number generator

...
1
vote
1answer
41 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
51 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
51 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
120 views

Optimizing Multiplication Table

I have a class that takes an array of integers and produces a multiplication table. ...
5
votes
1answer
73 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
230 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
42 views
4
votes
3answers
181 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
59 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
77 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
75 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
55 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
98 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
36 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
47 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
89 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
48 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
118 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
208 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
67 views

Rails configuration variants for production / development environments

How can duplication be removed from this? ...
1
vote
1answer
56 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 ...