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
3 votes
2 answers
96 views

battleship game with two ships per player

I'm creating a battleship game in Ruby. Let me explain how it works: The game is played on 5x5 grids (one per player). Players have 2 ships each to place on their grid. A small ship (3x1 side) and a ...
user avatar
  • 31
2 votes
0 answers
43 views

Ruby OOP Mastermind Game Code Refactor

I have finished The mastermind game. Basically, it's a game that has 2 sides, codebreaker or codemaker. If you are a codebreaker, you are guessing the colour code that the computer has chosen. If you ...
user avatar
4 votes
2 answers
86 views

Ruby CLI TicTacToe

I have done Tictactoe game in Ruby. It is my first Object Oriented project in Ruby. I would like to separate all program into a few classes such as Player Board and Game. I want to use more OOP best ...
user avatar
0 votes
1 answer
66 views

Code for appending to a certain index of an array

I have a collection which, after the code has ran, looks something like the following: ...
user avatar
1 vote
1 answer
48 views

Rails controller to handle offers and payments for rental housing

I've been adding stuff a bit "blindly" to my controller and currently everything is working as it should, but the controller is gotten very messy. I'm using the gem ...
user avatar
  • 11
0 votes
1 answer
44 views

RSpec: Compound Expectations

It's an exercise from a RSpec-course, which I'm currently doing. Task: Create a compound expectation, which asserts the string sportscar starts with the substring "sports" and ends with the ...
user avatar
  • 3,758
0 votes
1 answer
55 views

User registration API

Would love some feedback on this simple API implementation with Ruby on Rails. Have I used proper naming conventions, readable/manageable code, optimal approaches, etc? As I'm still learning Ruby on ...
user avatar
  • 103
1 vote
0 answers
37 views

Unpack a flattened hash into Hash/JSON

The following JSON ...
user avatar
4 votes
2 answers
76 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-...
user avatar
  • 183
3 votes
1 answer
70 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 ...
user avatar
1 vote
2 answers
70 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 ...
user avatar
0 votes
1 answer
57 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 ...
user avatar
2 votes
2 answers
85 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? ...
user avatar
-2 votes
2 answers
43 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 ...
user avatar
1 vote
2 answers
51 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 ...
user avatar
  • 107
0 votes
1 answer
81 views

Ruby: Chaining methods vs methods with arguments?

I started with the following module: ...
user avatar
  • 135
3 votes
1 answer
112 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 ...
user avatar
  • 135
2 votes
1 answer
62 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: ...
user avatar
1 vote
1 answer
61 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 ...
user avatar
3 votes
2 answers
113 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 ...
user avatar
  • 33
1 vote
3 answers
111 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 ...
user avatar
0 votes
2 answers
131 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 ...
user avatar
0 votes
3 answers
61 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 ...
user avatar
1 vote
0 answers
67 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 } ] ...
user avatar
  • 193
2 votes
1 answer
104 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....
user avatar
4 votes
1 answer
72 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. ...
user avatar
  • 193
1 vote
1 answer
56 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 ...
user avatar
1 vote
1 answer
65 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 ...
user avatar
2 votes
1 answer
146 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 +...
user avatar
  • 45
1 vote
1 answer
53 views

Ruby: Database Authentication Module

I have created a module that validates the credentials against different databases. ...
user avatar
3 votes
3 answers
201 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? ...
user avatar
  • 211
1 vote
2 answers
148 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! ...
user avatar
  • 41
-2 votes
1 answer
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 ...
user avatar
  • 117
1 vote
1 answer
144 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 ...
user avatar
3 votes
2 answers
181 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 ...
user avatar
  • 41
2 votes
2 answers
145 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, ...
user avatar
  • 41
1 vote
1 answer
41 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 ...
user avatar
  • 211
1 vote
2 answers
280 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 ...
user avatar
  • 211
-1 votes
1 answer
71 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. ...
user avatar
  • 211
1 vote
0 answers
64 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 ...
user avatar
4 votes
3 answers
91 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 ...
user avatar
  • 41
1 vote
0 answers
50 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: ...
user avatar
  • 3,758
1 vote
1 answer
418 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 ...
user avatar
  • 41
1 vote
2 answers
95 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 <...
user avatar
1 vote
1 answer
27 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: ...
user avatar
  • 3,758
4 votes
1 answer
145 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 ...
user avatar
3 votes
1 answer
63 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 ...
user avatar
1 vote
1 answer
223 views

Caesar Cipher, done in Ruby

It's an assignment from the Odin Project. Here's my implementation: ...
user avatar
  • 3,758
1 vote
1 answer
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 ...
user avatar
5 votes
2 answers
158 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 ...
user avatar
  • 3,758

1
2 3 4 5
33