Ruby is a multi-platform open-source dynamic object-oriented interpreted language created by Yukihiro Matsumoto (Matz) in 1993.

learn more… | top users | synonyms

-2
votes
0answers
7 views

I am trying to pass some RSPEC Tests and not sure how [on hold]

I am new to Ruby and trying to pass some RSPEC tests to write a tic tac toe game. Can anyone help with this? Here are the following tests: ...
5
votes
2answers
43 views

Transposing a 2D array

Would you have any suggestions for improvements for the code below? ...
3
votes
2answers
108 views

Logging to a File vs UDP

I'm trying to understand where my ruby implementation of this fails and hoping for an expert to shed some light on this situation. I've tried to make this a very simple example with the idea that ...
3
votes
3answers
71 views

Minimum coins algorithm in Ruby

I am working on a puzzle to find the minimum number of coins needed to buy a product. I am given three coins: 1 3 5 and also a number representing the price of a product: 11 The answer here ...
1
vote
0answers
19 views

Initializing a new user

I have a method in my rails project that initializes a new user by copying some properties of another. The method should also retain entered parameters if saving the new user is rejected. Rubocop ...
4
votes
2answers
82 views

Transforming an array in Ruby

I watched a presentation by Dave Thomas on Elixir where he gave an example problem that he solved using functional programming. He mentioned using Ruby to solve the same problem, but did not show an ...
1
vote
1answer
28 views

Empty product model

I don't think I am using MVC concept in Ruby on Rails properly. Model accesses db, controller works on logic and view displays information/data. But in my below code, My Model code is empty. Can ...
2
votes
2answers
70 views

Applying limit and offset to an array

I'm refactoring an old gateway and came across the following method: ...
3
votes
1answer
45 views

User search controller

I am using the ruby sunspot gem to create a search users function on my site. It works fine and the users controller for the index page where there is a search form is this ...
6
votes
3answers
104 views

SPOJ Adding Reversed Numbers

Recently, I was taking up this challenge and choose my favorite language 'Ruby' to do it. My following solution got accepted (Gist). For each test case, I am to reverse two numbers, add them, and ...
2
votes
4answers
80 views

Reduce 'Assignment Branch Condition Size'

I have a method in my Ruby code that sets the default name for my model. Rubocop complains that Assignment Branch Condition Size is too high, 21.24/15. How can I improve this? ...
3
votes
1answer
41 views

Rspec - testing basic functionality - redundant testing?

Being pretty new to testing, I was wondering how many of these tests make sense. restaurants_controller_spec.rb ...
5
votes
2answers
58 views

Plays a game of Tic Tac Toe

As part of the odin project I've written this bit of code that allows two users to play a game of Tic Tac Toe. I'm still a relative newbie to Ruby and to coding and am guessing that there are much ...
3
votes
4answers
227 views

Splitting an array at commas

I was given a file of size 46KB full of names (around ~5000), in the format as shown below: "MARY","PATRICIA","LINDA","BARBARA","ELIZABETH"..."DARRELL","ALONSO" ...
2
votes
2answers
25 views

Calculator in Ruby

I have created a calculator in Ruby. I am using Ruby 2.1.0. I'm fairly sure that someone will be able to improve this, as I am quite new to Ruby. ...
2
votes
0answers
18 views

Automatic flowchart generator

I wanted to see graphically what my programme was doing so I wrote this automatic flowchart generator: ...
4
votes
2answers
38 views

Simple Ruby directory navigator functions

In the process of writing scripts to work with CSVs and other files of the like I found myself in the need of a way to navigate and select files for various purposes. I wrote the following function ...
0
votes
0answers
19 views

Jekyll plugin for creating CSV files

I recently created a gem for Jekyll plugin to create some CSV files. I put a little more effort into it and tried to make it something that others might be able to use. I'm a little lost on how to ...
3
votes
0answers
22 views

Spam classifier

I wrote a small script to get the probability of a given text to be spam. I downloaded some ham (good content) and spam (bad content) text from the internet. The spam corpus is a 1.8 MB txt file, and ...
2
votes
1answer
28 views

Project Euler #11 in Ruby and some Iterations

Question: Given a 20x20 Grid of integers, find the greatest product of four adjacent numbers. (up, down, diagonal, reverse diagonal). ...
3
votes
1answer
43 views

Project Euler #10 in Ruby. Three ways to sum primes below 2 million

Question: Add all prime numbers smaller than 2,000,000. The first method is done by deriving own is_prime? method: ...
4
votes
1answer
115 views

Project Euler #8 in Ruby

Question: For a 1000-digit number, find the 13 adjacent digits which gives out the largest product. My code goes like this: ...
4
votes
1answer
27 views

Project Euler #6 in Ruby

Question: Difference between the Sum of squares from 1 to 100 and the square of sums of 1 to 100. Answer in Ruby: ...
2
votes
2answers
28 views

Project Euler #5 in Ruby with Prime class

Question: Smallest positive number that is evenly divisible by all of the numbers from 1 to 20? I tackle the problem with reference to how I solved #3, which is using the ...
-1
votes
0answers
18 views

Parsing lines and processing elements

The method process_open_elements decides the fate of process_block elements or runs directly. How can this be refactored to be ...
3
votes
2answers
90 views

Building a chain of responsibility in Ruby to apply transformators on an object

I try to make a middleware stack system in the rack way (but not for HTTP request). Here is the main class: ...
2
votes
1answer
45 views

Move and rename images into separate folders

Basically, we came up with this task at work. I was wondering if there's a shorter and cleaner way of doing the following in some other language (or even improving what I did with Ruby). We have a ...
3
votes
3answers
70 views

Frog jumping algorithm

I took a test on Codility for coding the minimum number of frog jumps to reach from position x to position y: A small frog wants to get to the other side of the road. The frog is currently ...
3
votes
2answers
40 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
22 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
31 views

Ruby singleton for logging

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

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
30 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
49 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
28 views

Rspec test reuse code for before_filter and method

Consider following example (controller): ...
1
vote
0answers
29 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
81 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
60 views
0
votes
0answers
26 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
32 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
56 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 ...
5
votes
1answer
46 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
vote
0answers
36 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
53 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
80 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
43 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
62 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
84 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 ...