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
0answers
24 views

Unpack a flattened hash into Hash/JSON

The following JSON ...
2
votes
2answers
28 views

Jekyll plugin which bundles files into a zip archive

I am not a Ruby developer but cold-reading existing Jekyll plugins I implemented one to bundle files in a zip archive and open sourced it on GitHub. What do I need to fix to make it look more Ruby-...
3
votes
1answer
64 views

Migration in a bioinformatics application that changes a column name and explains the rationale

This very short piece of code is a migration in which a column name is changed to be more descriptive. It is part of a larger bioinformatics application written in RoR that parses the output of ...
1
vote
2answers
29 views

Refactoring Ruby recharge REST API wrapper by using class variables

I am trying to create an API wrapper for recharge (A Shopify subscription service), I am using the HTTParty gem ...
0
votes
1answer
40 views

Library Program in Ruby with Class

I have been learning Ruby for 2 weeks. Today my bootcamp teacher taught Ruby Class and gave me homework. I coded simple library program. But I think the code is smelling bad. How can do better the ...
2
votes
2answers
55 views

Number guessing game in Ruby

I am a newbie in Ruby. I want to learn Ruby and I want to learn clear code in Ruby. I coded a number guessing game but my code is smelling bad. How I can do better code? ...
-2
votes
2answers
42 views

How can I make BalanceService PORO I wrote better of any code smell? [closed]

I wrote this method which I think is not effective as it doesn't respond to the missing method when I use the PORO Class. BalanceService ...
1
vote
2answers
50 views

Querying and rendering an HTML table of ISP performance statistics

I have multiples measurements and I want to render it into tables like this Measurements Operator browsings FTP DL FTP UL Location Event Date Operator avg min max avg min max avg min max Verizon ...
0
votes
1answer
70 views

Ruby: Chaining methods vs methods with arguments?

I started with the following module: ...
3
votes
1answer
100 views

Reshape hash of hashes into array of modified hashes without using nested each?

My goal is to write more idiomatic ruby when working with nested data structures. More specifically, I need to break my habit of looping through everything with ...
2
votes
1answer
55 views

Singleton in Ruby without using Singleton module or class variable

When I need a singleton class in my Ruby code (for example, single logger for multiple classes) I usually use code like this: ...
1
vote
1answer
57 views

How to reduce code in hash created using Database and Params in rails

I have wrote following solution for one answer but I want to refactor to make it more simple and readable. I am receiving params ...
3
votes
2answers
100 views

Finding minimum steps required to traverse from source to terminal

Hello everyone this is my first post here so please do critique my post if there's anything. I have made a program intended to pass a programming challenge on open.kattis.com, here. It should do as ...
1
vote
3answers
102 views

Advent of Code 2020, Day 10 in Ruby

I'm an amateur programmer making a career change into web development. I've found Advent of Code challenges are great way to sharpen my skills. I've cleaned up this solution for Day 10, 2020 as much ...
0
votes
2answers
106 views

Insertion Sort Implemented in Ruby

I'm a new programmer and I'm periodically going into the Intro To Algorithms CLRS textbook and trying to translate pseudocode into Ruby for skill practice. This is my implementation/translation of ...
0
votes
3answers
50 views

Ruby: possible Poker holds for a hand of length n

Hello everyone and thanks in advance for taking the time to read my post!! In the process of learning Ruby, I'm writing a video poker machine that analyzes hands represented by arrays of Cards, like ...
1
vote
0answers
60 views

Addition/subtraction of Ruby arrays

Let's say I have this array. items = [ { amount: 100, add: true }, { amount: 50, add: false }, { amount: 100, add: true } ] ...
2
votes
1answer
90 views

How can I make this CSV Importer code better of any code smell?

I wrote this method a few years ago in a Ruby on Rails project, which I think I am not proud of. How can I make this code better to show in-depth professionalism in Ruby? lib/merchant/web_csv_importer....
4
votes
1answer
62 views

Generating product variants in Ruby

Based on the sample variants, I need to get all combinations of all variants. In the example I have 3x3x2=18 variants. ...
1
vote
1answer
54 views

Ruby Symbol Table implementation using Binary Search

I'm currently going over Robert Sedgewick's Algorithms book. I implemented a Symbol Table using two parallel array one for keys and one for values. The keys array is ordered and the Symbol Table uses ...
1
vote
1answer
60 views

What changes can I make to simply this function that groups parameter key value pairs

I am writing a function that can be used in a ruby script that will match the parameter and values together so the script can use them in an intelligent way. The idea is if you were to run a script ...
2
votes
1answer
98 views

Idiomatic Ruby if/else in a Sinatra route

Apologies if this question doesn't fit the format here, seemed more appropriate here than SO due to the more nebulous nature of the question. Think mini tinyURL clone: POST to service to save the url +...
1
vote
1answer
51 views

Ruby: Database Authentication Module

I have created a module that validates the credentials against different databases. ...
3
votes
3answers
190 views

Better way to count the number of occurrences of a maximum number in the array in Ruby

I am trying to write a program to get the count of the maximum number in an array of integers. The below code is what I have written. Is there any better way to write this code in Ruby? ...
1
vote
2answers
120 views

Ruby Hangman Game

I'm still new to coding and self-taught. If anyone could take a look at my code for my Ruby Hangman game and give any tips or advice whatsoever, it would be greatly appreciated. I'm trying to improve! ...
-2
votes
1answer
37 views

Getting account status from a client [closed]

I have the following Ruby method. def get_status(creds) client = create_client(creds) status = client.account_status client.close_session status end ...
1
vote
1answer
125 views

Priority Queue implementation for top k frequent elements leetcode in Ruby

While working on the following leetcode problem: https://leetcode.com/problems/top-k-frequent-elements/ I used a Priority Queu implementation in Ruby. I have learned how to implement a Priority Queu ...
3
votes
2answers
164 views

Reverse the words, move the vowels and downcase everything

I'm brand new to Ruby. The function takes in a string of any number of words, and reverses the order of the words. Also, for each word, it takes the vowels and moves it to the end of the word. It also ...
2
votes
2answers
112 views

Ruby Mastermind game project with AI

I'm self-learning and pretty new to coding and created a Mastermind game in Ruby. Any general feedback or advice whatsoever would be greatly appreciated. The game is completely functional right now, ...
1
vote
1answer
40 views

Should methods be inside classes? in Ruby

I have coded more in Python but I am learning Ruby now. So I am trying to write a solution to create a family_tree and add and get relationships. The code below is ...
1
vote
2answers
151 views

Return nil after loop and also in unless block in Ruby

I have a working code as below. Is there any better way to return nil after the each loop and ...
-1
votes
1answer
70 views

Correct way to define variables and methods in Ruby [closed]

I am trying to write a Person class in Ruby which has some methods and properties. The below is how I have implemented it now. ...
1
vote
0answers
59 views

Random Word Chain Finder in Ruby

Wrote this program out of curiosity after initially solving the Word Chains puzzle. Explanation of puzzle in link below. http://rubyquiz.com/quiz44.html NWordChains#find_word_chains will take in a ...
4
votes
3answers
75 views

App to seed DB, generate CSVs, and export individually or in complex zip files Rails 5

I have an app whose sole purpose is to seed data files and add the data to different CSVs which are zipped and exported by the user. My application controller is filled with lines that all look like ...
1
vote
0answers
40 views

Custom include? method for a substring

Task: Write a function which returns true if a given substring is found within a given string. If the substring isn't found, then return false. My implementation: ...
1
vote
1answer
304 views

Ruby Tic-Tac-Toe two-player

As a preface, I'm very new to coding (self-learning) so if you notice any bad habits please let me know, it would be GREATLY appreciated. I'm self-learning Ruby so I don't really have a frame of ...
1
vote
2answers
89 views

Parser for file made up of sections

I'm parsing a file made up of various sections. I have a current_section variable that tracks which portion of the file I'm currently processing and the following <...
1
vote
1answer
26 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: ...
4
votes
1answer
125 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 ...
3
votes
1answer
56 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
142 views

Caesar Cipher, done in Ruby

It's an assignment from the Odin Project. Here's my implementation: ...
1
vote
1answer
41 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 ...
5
votes
2answers
105 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
66 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
118 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
131 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
105 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
67 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 ...
2
votes
1answer
112 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
42 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 ...

1
2 3 4 5
33