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
11 views

Write your implementation of Ruby's String#count method

The task is to write a simplified version of Ruby's String#count method oneself. Simplified because it doesn't have to have the negation and sequence parts of the original. Here my solution: ...
3
votes
1answer
46 views

Solution to the n-queens puzzle in Ruby

I started studying programming in January of this year and found a free online course that teaches Ruby. Below is my solution to the Eight Queens problem. I wanted my solution to be able to return any ...
2
votes
1answer
41 views

Finding the lowest perfect square that can be added to a number to make another perfect square

The code below returns the smallest perfect square that can be added to a number n to result in a perfect square. It works perfectly fine but I need it to run ...
1
vote
1answer
30 views

Caesar Cipher, done in Ruby

It's an assignment from the Odin Project. Here's my implementation: ...
0
votes
1answer
29 views

Ruby script implementation

I created a script to automate the task of uploading a CSV file to Box. I have a couple of files a Box client and a MySQL client. I create an instance of both on the function.rb file which is the one ...
4
votes
2answers
44 views

Ruby function to capitalize all words in a string

The task is to write a function, which capitalize the first letter of all words in a string. For this we'll class a word as any characters separated by a blank. Because the standard ...
1
vote
2answers
42 views

API Get Request to pull data from an online database

This code gets detailed information about a particular game from an online database using an API Get request. The question I have doesn't pertain to the request but is more about the code itself. The ...
3
votes
1answer
102 views

Ruby simple interactive interpreter

This is a solution to this problem: https://www.codewars.com/kata/53005a7b26d12be55c000243/train/ruby The task is to make a simple interpreter that will take expressions and calculate the results. I'...
1
vote
1answer
26 views

Ruby Exercise: Implement your own “#group_by” method

Task: "Implement a method 'gruppiere', in a way that it can be invoked on all enumerable objects (Enumerable). The method receives a block and returns a hash. The items of the enumerable a grouped ...
1
vote
1answer
28 views

Ruby - Sending commands to multiple servers using Net::SSH

The idea At my work, I'm tasked with retrieving logs for a list of online orders from a total of 12 servers. To do this, I SSH into them (with a jump host in between) one by one, run the script for ...
2
votes
0answers
31 views

Profitwell API wrapper build as Ruby gem

I've created my first gem in Profitwell API wrapper https://github.com/eebasadre20/profitwell. I love to get some feedback, comment, or suggestion on the code structure, method implementations, and so ...
1
vote
1answer
30 views

Linked List implementation in Ruby

I was working on Leet code design a Linked List problem. My solution with a @tail pointer, althought it added complexity it made adding to tail O(1), also having a ...
0
votes
0answers
32 views

mergeSort implementation in Ruby

I'm currently going over Robert Sedgewick Algorithms book and I'm trying to recreate his Java implementations in Ruby. I would like to know If I'm following best practices. I try to use clean code ...
2
votes
1answer
44 views

Presenter pattern implementation

I've recently discovered patterns and decided to implement Presenter pattern inside a pedagogical project. I spent few days playing around with different implementations, reading some Gem's source ...
1
vote
0answers
242 views

Building google maps inside a ruby on rails application

This is a basic map that was built: To render it, you would put this in the .html.slim files .acme-map-container-4 data=map_identifier(resource: @warehouse.id) ...
1
vote
0answers
42 views

Encapsulating Logic to Reuse in Various Contexts

I'm experimenting with ways to reuse code throughout a Rails web app. I'm interested in feedback concerning one such approach! Context A user's request may be scoped to a physical location so that ...
2
votes
1answer
50 views

Rails 6: Attaching Devise current_user.id to form submissions

In my Ruby on Rails 6 app: I have a User class built with Devise, and I scaffolded a List class where each List should belong_to a User. I want Lists created through my app to be automatically ...
1
vote
1answer
46 views

FizzBuzz encapsulation In Ruby (identifying and separating concerns)

I'm working on an article about encapsulation in OOP, and I'm using the FizzBuzz problem to demonstrate what I think is so great about it. I'm hoping to share this with developers that might also be ...
0
votes
1answer
62 views

Case of Cyclomatic Complexity

I'm trying to recreate the method inject (Works like Reduce) from ruby Enumerable Module. Using Rubocop (A Linter) I got the error: ...
1
vote
1answer
43 views

Ruby parallel assignment

I recently wrote the following code: ...
1
vote
1answer
42 views

Return values from array A in the order they are in array B

So my question is the cleanest way to do #product_panels_for below: ...
1
vote
1answer
40 views

custom hash from group_by hash

I am trying to create a custom hash from a table. User has many transactions. A transaction has a ...
1
vote
0answers
38 views

Advent of Code Day 3, how to optimize my ruby solution?

I have solved the 3rd day puzzle of Advent of Code but wanted some feedback on my solution. The puzzle here wants to find where two jumbled wires intersect closest to the origin. Puzzle input is ...
2
votes
1answer
26 views

Comparing verbosity of algorithmic Ruby class

At a high level, I'm writing a Ruby class that compares components on two differing versions of the same JSON structure, which in turn decides whether or not said elements should be updated on a PDF ...
2
votes
1answer
112 views

Remove multiple array elements by indices

I prepared a method to make possible to select elements of the array except for some indexes. ...
2
votes
1answer
72 views

Tentative to transform this scrape script into a class object program

From the last few days I have been studying scrapping webpages and for further development I challenge myself to transform the script I have created into a class which will receive inputs from a user. ...
2
votes
1answer
48 views

Ruby coin toss probability tool

I haven't been programming for a while, I wanted to do a simple project to warm myself up and get back into the game; I made this simple tool that finds the probabilities of coin toss combinations. ...
2
votes
1answer
55 views

Change architecture of Ruby app to be more object oriented, readable

I'm working on a Slack bot for service desk which sends direct message to user on a Slack when their ticket will be on user_action_needed status. I'm using AWS ...
1
vote
1answer
67 views

Rails: create a relationship between comment and user

I'm trying to connect the create of a comment to the current_user. I have a model comment which is a polymorphic association. <...
1
vote
1answer
30 views

Concatenate unless note [closed]

mails = [] mails.concat(@note.cc_emails) unless @note.cc_emails.nil? mails.concat(@note.to_emails) unless @note.to_emails.nil? Everything what I'm doing here is ...
2
votes
2answers
119 views

Rock, Paper, Scissors completed game

I have just completed my first Ruby OOP project. Fairly simple but still a bit time consuming as I am still learning the language. I would like feedback and ways I can improve on this and make the ...
4
votes
2answers
68 views

Rails Helper to display rating in stars

Using Rails 6. Here's a piece that I wrote just to display number of stars. Obviously I am disgusted by my own code. How would you refactor? ...
3
votes
0answers
50 views

Assigning raffle numbers to users in Rails

Background One part of our Rails app is running a Raffle, usually twice a month, with around 600k entrants each round. Each raffle ticket record will have at least a unique raffle number (consisting ...
2
votes
0answers
63 views

Ruby script for automating software install on a brand new Linux OS

I have some scripts to automate software install, apply some configurations and so on after installing a new system. I used to have them as bash scripts but it was generally a poor idea. I have ...
3
votes
1answer
108 views

RSpec shared example for CRUD Controllers that might be nested or not

I've been trying to create a shared example to quickly and efficiently test controllers with CRUD operations that might also be nested. I came up with this ...
1
vote
2answers
61 views

Removing duplicate hashes in an array while keeping count of the times the hash was present

I have an array of hashes (price_params['items']) where each item has a key called quantity what I'm trying to do is to clean ...
-1
votes
1answer
34 views

Translator method failing to translate two words [closed]

Sorry if this has been answered to death—I'm working on a pig latin translator for Odin Project. The code below works fine for individual words, but when it receives two words ("eat pie"), the output ...
2
votes
1answer
100 views

Ruby code to parse and analyze social media stats in json format

What do you think about this code I wrote. It reads several json files ( I attached them as pastebins) and the code outputs summary information calculated from the input. ...
7
votes
1answer
74 views

Incremental, encrypted backups for git

I would appreciate any review of the following script I recently posted on GitHub (gitcrypto). Most notably, I would be interested in a review of the cryptographic aspects (I am not an expert in this ...
1
vote
1answer
60 views

Ruby: Remove middle node from Linked List

Currently, I'm going over the CTCI, I'm working on the problem removing the middle node. I'm using Ruby to go over these problems. I have the following solution. ...
3
votes
1answer
54 views

Store personal data for later use

I'm new with Ruby and am trying to improve my coding skills. This program gets personal information for three people, and then prints them. It works, but I'm sure it's not the best and certainly not ...
2
votes
1answer
196 views

Easily interacting with two external apis

Recently I rewrote some methods/functions written by a previous developer mostly due to the fact that the previous implementation overdid the whole 'OO' thing, and used inheritance inappropriately. ...
1
vote
1answer
198 views

better multiple fields validation on ruby/rails

I have a form for an item (Job Item), that has sets of 2 fields based on a type. field and field + _dolar e.g: ...
4
votes
1answer
68 views

Repeater for blocks of Ruby

I've written a module for repeating blocks of code, generally to cover issues related to eventual consistency and testing screen elements which may take some time to fully load. It looks like this: <...
2
votes
1answer
52 views

Command-line implementation of Mastermind

I just finished this command-line implementation of the Mastermind board game that allows two players to play against each other. I'm fairly new to Ruby, but I think I did a decent job with this. ...
2
votes
1answer
92 views

Remove duplicates from an unsorted Linked List in Ruby

Currently I'm going over the cracking the coding interview. I'm in the Linked List 2.1 question which is as follow: Remove Duplicates, write code to remove duplicates from an unsorted Linked List....
1
vote
1answer
32 views

Rails initializer to be more clean [closed]

I need a little bit of refactor my initialize method because I think it will make initializer more flexible and readable. ...
2
votes
1answer
67 views

Dynamically combine ActiveRecord Relation results [closed]

This isn't the actual use-case I have but for simplicity, let's say I have an ActiveRecord Animal model in a Rails app. The Animals have a name (string) and ...
0
votes
1answer
33 views

ActiveRecord Query for many to many association

I have two Models in my Rails 6 / PostgreSQL application which have a many to many relation; Car and Driver. The goal is to get ...
2
votes
2answers
59 views

Calculating p-value for Welch's t-test

I am attempting to translate some of my Perl code to Ruby, from http://rosettacode.org/wiki/Welch%27s_t-test I am a very very beginner with Ruby, but I have verified that this is producing the ...

1
2 3 4 5
32