Questions tagged [ruby]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
42 views

Refactored code for updating user password, email and other info

I have to update user email and password if they are present in the params, I have other user information also which can be updated. this is the method I have written, but it doesn't seem like a good ...
3
votes
2answers
447 views

Making Anagrams

Task: given two strings, that may or may not be of the same length, determine the number of characters you must delete to make the two strings anagrams of each other. My solution: ...
1
vote
2answers
204 views

Resetting a password

I am trying to reset a password when password_reset_token is received in the controller. But it's becoming a long if ...
3
votes
1answer
176 views

Ruby & OOP: FizzBuzz Game

I would like a more elegant solution for this problem, I think the FizzBuzzArrayBuilder class is not used properly. Also can those ...
2
votes
0answers
154 views

LeetCode Minesweeper solution in Ruby

This is my solution to this LeetCode problem. Essentially you want to get the next board state for a Minesweeper game. All test cases passed and the submission was accepted on leetcode. The ...
0
votes
2answers
55 views

A class that uses a few other classes to generate an email

I seem to find my self writing a lot of classes like the below where there seems to be some kind of send method that just calls a bunch of other methods. Is this ...
2
votes
0answers
727 views

Rails CRUD feature specs (RSpec and Capybara)

The following feature spec tests CRUD operations for the users resource in a Rails 4.2.8 application. It includes tests for filtering, sorting and pagination ...
0
votes
1answer
56 views

rails method for transaction type

I am trying to make a rake task but after completion my code i realized i need some refactorization. How could I do refactorization of the following code? ...
2
votes
1answer
632 views

Rails5/Devise/Omniauth (Multiple Providers)

I spent the better part of the last two days getting this to work, but it finally is working, but it feels extremely redundant. I am following a belongs_to method ...
3
votes
1answer
140 views

Rspec test to confirm rejection of four invalid dates

...
3
votes
0answers
134 views

Codingame: Great Escape bot in Ruby - Follow-up

This is a follow-up to Codingame: Great Escape bot in Ruby. As mentioned there, my first reasonably sized Ruby project is a bot for CodinGame's Great Escape contest (here is a sample gameplay video). ...
5
votes
1answer
1k views

Rails & RSpec - Testing API with request specs and shared examples

I have written the following shared examples which are used in multiple request specs to test a namespaced RESTful JSON API. Application details: Rails 4.2, RSpec 3.5, Devise for authentication and ...
0
votes
1answer
55 views

Ruby class to encapsulate Retrying (for instance, with email)

One of my clients sends quite a few emails a day ... I would think over 500. They are mostly reports to clients or employees. The volume has become sufficient that intermittent issues with gmail (like ...
-2
votes
2answers
4k views

Case statement with array includes? [closed]

What is the best practice to implement case checks using arrays in Ruby? ...
4
votes
2answers
72 views

User and picture models

I have the following models: User Picture Variant User has_many pictures, picture has_many variants. Variant has value price ...
3
votes
1answer
499 views

Controller tests (Rails 4.2 and RSpec 3.5)

The following code is a controller spec used in a Rails 4.2 application with RSpec 3.5. I would greatly appreciate your suggestions on how to improve it (e.g., efficiency, readability, maintainability,...
3
votes
2answers
801 views

Group array by sums

I have the following code that takes an array, and groups it by the sums of its elements: ...
5
votes
2answers
301 views

Codingame: Great Escape bot in Ruby

(EDIT: I incorporated a lot of the feedback from the answers, and posted a follow-up question here: Codingame: Great Escape bot in Ruby - Follow-up) I started working on some code challenges at ...
-1
votes
1answer
160 views

Merge sort for an integer array in Ruby

I've implemented merge sort an integer array. Should I change them to more meaningful names? Overall, any further suggestions on this code? I would like to improve my coding style and to shorten the ...
3
votes
2answers
615 views

Convert decimal to binary and find the maximum number of consecutive 1's in the binary

Task: given a base- 10 integer, n, convert it to binary (base-2). Then find and print the base- 10 integer denoting the maximum number of consecutive 1's in n's binary representation. What can you ...
1
vote
2answers
50 views

Weekly job to create or update the lessons in all locations

I'm working in a project with the following structure. A location can have many timetables with many lessons. I need to perform a job in all locations every sunday to create or update the lessons. <...
7
votes
0answers
96 views

Stable variation of built-in sort

Ruby's built-in sorts are unstable. The stable_sort gem monkey-patches Ruby's built-in library to have stable sorts which include nearly all the functionality of the built-in sorts, but with the ...
3
votes
0answers
220 views

Ruby on Rails portfolio website

I've been learning Ruby on Rails for the last few weeks. I've decided to do a portfolio website using Ruby on Rails to showcase all of my projects. Can you look through my code to see what you think? ...
5
votes
3answers
2k views

CodeWars kata 'Sum Of Pairs'

I need help in optimizing my code for this challenge. I think my algorithm is fine and I pass all sample tests but get took longer than 12000ms to complete error for final one. I guess there are a ...
1
vote
1answer
410 views

Extract list of selected contractors by matching serialized array in Rails

I'm working on an application where I have a Company model setup as follows: ...
3
votes
1answer
318 views

Ruby wrapper for Instagram API

I've created my first gem as Instagram API wrapper https://github.com/agilie/instagram_api_gem. I would be very pleased if you give me some feedback on code organization, methods elegancy and so on. ...
4
votes
7answers
2k views

Display related records, if they exist, in Rails view

Is this much logic in view is justified to check for the presence of record? ...
1
vote
0answers
765 views

Unit-testing authorization policies in Rails with RSpec

The following specs test the authorization setup of the Post resource in a Rails 4.2 application. The Pundit gem is used for authorization but I believe the specs ...
6
votes
0answers
276 views

Solve alphametics puzzles in non-brute-force, iterative manner

The goal: Trying to optimize solution for the alphametics problem on exercism. From the question text: Alphametics is a puzzle where letters in words are replaced with numbers. For example ...
1
vote
3answers
1k views

Count has_many relationships

I have 3 models: Import, Product, Values. An import has_many products. A product has_many values. I want to find the product with the highest values count and the sum of all values for all those ...
0
votes
1answer
77 views

Array even and odd indexes sorting and printing its values

I'm looking for a more elegant solutions of this task. Task: Given a string, print its even-indexed and odd-indexed characters as space-separated strings on a single line. Input Format: The first ...
4
votes
1answer
1k views

Validate if Sudoku is correct

Given a two-dimensional array, Sudoku class can create NxN Sudoku where N = size^2. Assume that the user gives only valid NxN matrixes for the constructor. Method <...
1
vote
0answers
225 views

Rails - updating and deleting exactly 2 children of the parent model

Requirements A Phrase can have many Translations, which are in turn a Phrase; thus, the ...
2
votes
1answer
356 views

URL whitelist class

I'm trying to make a class for safe redirection of URLs. Redirecting URLs is something you can have in a get parameter, for example: ...
3
votes
1answer
326 views

Redis lookup with a default value

I have some code to perform a redis lookup, but if the key to look up either doesn't exist or there's an issue connecting to Redis at all, it will use a default value. The logic currently looks like ...
3
votes
2answers
66 views

Rails method to match users according to language fluency level

This code works fine, but I'm still learning, and feel like there is a more Railsy way to write this. Is there a good rails ActiveRecord method I should learn more about? Please let me know if you ...
3
votes
1answer
1k views

Finding the middle permutation

This method finds all permutations of a string and stores them in a sorted array. It then returns the element in the middle of the array. ...
2
votes
2answers
61 views

Persist relation to a class (and not a class instance) in Ruby on Rails with Mongoid

Assume my users can subscribe to several plan_types. I want to define those plans as classes, and be able to keep, for each user, a reference to a subscription_plan and also a presubscription_plan. ...
3
votes
1answer
268 views

Sudoku solver using backtracking, in Ruby

I wrote the below Sudoku solver, using Backtracking. Would love to hear your comments on the approach, and how I can improve readability/performance: ...
2
votes
2answers
112 views

Extracting an IP address from a hosts file by hostname

I am currently working with Vagrant for the first time, and therefore also working with Ruby for the first time. I have a specific hostname and IP address I would like set for my VM, both of which are ...
0
votes
1answer
46 views

Checking whether any of some large collection of attributes has changed [closed]

I have to check a large number of attributes and do something if any of them have changed. However, right now there are way too many or statements. Is there a better way to do this? ...
4
votes
3answers
1k views

Ruby banking system program

As a beginner I'd like to get any kind of feedback. The more the better. Any optimization and style mistakes? ...
1
vote
1answer
94 views

Print lyrics of 99 Bottles of Beer

I read 99 Bottles of OOP, and one of the offhand comments was that doing the 99 bottles problem with composition was another route that one could take (the book used inheritance). Here is my attempt. ...
1
vote
2answers
1k views

Setting unique code to model before creating (ruby/rails)

I have a Table model that needs a unique code. I have a method creating the code (and making sure it's unique), but I have the same line ...
4
votes
2answers
396 views

Tower of Hanoi solver in Ruby

Solved the classic Tower of Hanoi problem in Ruby, using recursion. Would love your feedback on this. ...
5
votes
1answer
242 views

Print combinations of balanced parentheses

Solved the below problem. Would love to hear your feedback, especially on performance improvements (granted, the solution should remain recursive). Especially concerned about the ...
0
votes
1answer
101 views

List User Online Status

I'm using Rails with MongoDB for database. In my apps I have 1 action for displaying list of users. User has name, image, ...
3
votes
0answers
67 views

Space efficient revision history storage with diffs

I've written a tool to store a files history more efficiently by only generating diffs and storing them whereas whole file would otherwise have to be stored. I would like to to hear about ways to ...
1
vote
1answer
129 views

Ruby on Rails Messaging board

I would definitely love some feedback on this message board app I made. I been doing front end development for the most part and I just want to keep my backend chops up. Let me know anywhere that can ...

1
3 4
5
6 7
32