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
0 votes
1 answer
38 views

Ruby-function for reading, parsing a text-file, removing data-duplicates

Task description: Implement a generate_unique_phone_numbers function. The function shall parse the given text-file. Content-example: ...
michael.zech's user avatar
  • 4,212
0 votes
3 answers
94 views

Print last lines of file

Task Write a Ruby function, which accepts a path to a text file and returns a string consisting of the last n lines in reversed order, separated by commas. Example input file: ...
michael.zech's user avatar
  • 4,212
0 votes
1 answer
104 views

The simple calculator in Ruby

I wrote the simple calculator in Ruby. This is my first program in this language. I've switched recently from Python to Ruby. What do you think about my work? Thanks ...
lester's user avatar
  • 311
1 vote
3 answers
107 views

Ruby FizzBuzz using the ternary operator two times

Task: Implement a function which loops from 1 to 100 and prints "Fizz" if the counter is divisible by 3. Prints "Buzz" if the counter is divisible by 5 and "FizzBuzz", ...
michael.zech's user avatar
  • 4,212
0 votes
1 answer
69 views

Changes hash to allocate values as directed

Let's say you have a hashmap of sub-systems that a spaceship is currently directing power to and a second hash of sub-systems where the power should now be directed to. Create a function that returns ...
Nelo's user avatar
  • 125
4 votes
1 answer
398 views

Write a simple, clean error message without a backtrace and exit on failure

I want to write on failure to either STDOUT or STDERR a clean, simple error message for the user, without the (verbose) ...
Timur Shtatland's user avatar
2 votes
2 answers
129 views

Ruby SFTP client

I'm on Ruby for three weeks and now I want to learn more. Please review this SFTP client and suggest any necessary changes. ...
user avatar
3 votes
1 answer
47 views

Solution to Codejam 2022 1C (Letter Blocks) in Ruby

The following is my solution to the Letter Blocks problem from Codejam 2022: https://codingcompetitions.withgoogle.com/codejam/round/0000000000877b42/0000000000afe6a1. Problem It is a rainy day, so ...
Panic's user avatar
  • 287
2 votes
2 answers
79 views

Solution to a competive programming contest (Codejam 2011 1A)

The following is my solution to the killer word problem from Codejam 2011: https://codingcompetitions.withgoogle.com/codejam/round/0000000000433198/0000000000432fe2. In summary, we're playing Hangman. ...
Panic's user avatar
  • 287
1 vote
1 answer
147 views

Open a file, with a fallback path if it doesn't exist at one location

I am parsing a file that exists in either app/components/ui or in app/components. If the one in the first dir (...
jeffci's user avatar
  • 248
3 votes
2 answers
89 views

Parse a document and returning uniqueness and total number occurrences

I am parsing a document and returning (1) uniqueness, and (2) total number occurrence. I believe my code can still be subjected to review. I would like a review of my code as I have even made it too ...
Afolabi Olaoluwa's user avatar
4 votes
2 answers
493 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 ...
Edouard's user avatar
  • 41
2 votes
0 answers
96 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 ...
theplaceofburak's user avatar
4 votes
2 answers
120 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 ...
theplaceofburak's user avatar
0 votes
1 answer
75 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: ...
Danny Goodall's user avatar
1 vote
1 answer
106 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 ...
Daniel's user avatar
  • 11
0 votes
1 answer
179 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 ...
michael.zech's user avatar
  • 4,212
1 vote
1 answer
139 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 ...
Jay's user avatar
  • 113
1 vote
0 answers
71 views

Unpack a flattened hash into Hash/JSON

The following JSON ...
Samuel Vijaykumar's user avatar
4 votes
2 answers
115 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-...
PhilLab's user avatar
  • 193
3 votes
1 answer
75 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 ...
Timur Shtatland's user avatar
1 vote
2 answers
202 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 ...
Artyrcheek's user avatar
0 votes
1 answer
160 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 ...
codescaptain's user avatar
2 votes
2 answers
189 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? ...
codescaptain's user avatar
-2 votes
2 answers
46 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 ...
Afolabi Olaoluwa's user avatar
1 vote
2 answers
67 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 ...
buncis's user avatar
  • 107
0 votes
1 answer
342 views

Ruby: Chaining methods vs methods with arguments?

I started with the following module: ...
Steve K's user avatar
  • 135
3 votes
1 answer
219 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 ...
Steve K's user avatar
  • 135
2 votes
1 answer
156 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: ...
Ivan Olshansky's user avatar
1 vote
1 answer
69 views

Group some given users according to their department

I have wrote following solution for one answer but I want to refactor to make it more simple and readable. I am receiving params ...
Kamal Panhwar's user avatar
2 votes
2 answers
154 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 ...
ma22om's user avatar
  • 23
0 votes
3 answers
118 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 ...
Kevin Andrus's user avatar
0 votes
2 answers
224 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 ...
John O'Brien's user avatar
0 votes
3 answers
93 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
163 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 } ] ...
dcangulo's user avatar
  • 193
2 votes
1 answer
188 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....
Afolabi Olaoluwa's user avatar
4 votes
1 answer
100 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. ...
dcangulo's user avatar
  • 193
1 vote
1 answer
64 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 ...
Steven Aguilar's user avatar
1 vote
1 answer
80 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 ...
jacksonecac's user avatar
2 votes
1 answer
187 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 +...
McDerp's user avatar
  • 45
1 vote
1 answer
56 views

Ruby: Database Authentication Module

I have created a module that validates the credentials against different databases. ...
Rajkaran Mishra's user avatar
3 votes
3 answers
228 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? ...
Lax_Sam's user avatar
  • 211
1 vote
2 answers
293 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! ...
mbcode's user avatar
  • 41
-2 votes
1 answer
40 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 ...
megas's user avatar
  • 117
2 votes
1 answer
225 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 ...
Steven Aguilar's user avatar
3 votes
2 answers
194 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 ...
whoami's user avatar
  • 41
2 votes
2 answers
292 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, ...
mbcode's user avatar
  • 41
1 vote
1 answer
48 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 ...
Lax_Sam's user avatar
  • 211
1 vote
2 answers
621 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 ...
Lax_Sam's user avatar
  • 211
-1 votes
1 answer
74 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. ...
Lax_Sam's user avatar
  • 211

1
2 3 4 5
33