Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
19 votes
2 answers
594 views

Count the occurence of nucleobases in DNA string

Inspired by this meta question I decided to take a look at Rosalind. Their first challenge seemed easy enough: An example of a length 21 DNA string (whose alphabet contains the symbols 'A', 'C', 'G', ...
2 votes
1 answer
45 views

Statistical function which computes the average work time in different months

It's a task from a Ruby-course, in which I'm currently enrolled: Ruby Course - Page Precisely it's one of the assignments for the first week. Following idea: Your are given a list in which finished ...
2 votes
1 answer
331 views

Add method to Ruby's Enumerable module that produces every nth element

The task is to enhance the Enumerable module with a method nth(). The method shall create a new list, which contains every nth-...
0 votes
1 answer
1k views

ruby rails 4 initialize and increment instance variables

I have been tinkering with various ways to clean this up and I was wondering if it is more ideal to break this into small methods or way to accomplish this on a single line? ...
1 vote
1 answer
80 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 ...
3 votes
0 answers
27 views

Using Pundit Policy Scopes with Searchkick Results

We are using Searchkick to run our elasticsearch and Pundit to authorize users for specific actions. Below is our module SearchkickScope that does it's best to ...
3 votes
2 answers
6k views

Breadth and Depth First Search in Ruby

I was tasked with building three individual methods; one to create a Binary Search Tree (BST), one to carry out a Breadth First Search (BFS), and one to carry out a Depth First Search (DFS). Create ...
1 vote
1 answer
45 views

Rails session after migrate from PHP (improved)

previusly I make a post for Session Logic for User Verification in Rails Migration. Now the improvement version following advice of the comments is here. The problem was the use of `` for executing in ...
2 votes
1 answer
72 views

Session Logic for User Verification in Rails Migration

This is a logic to create sessions on RoR 7.1.2 based on the last version of the website which was in vanilla PHP, with the upgrade I have to deal with the users that were already signed up but not ...
4 votes
2 answers
958 views

Function that takes a positive integer number and returns the next bigger number formed by the same digits

I am taking on this challenge on CodeWars. You have to create a function that takes a positive integer number and returns the next bigger number formed by the same digits: ...
2 votes
1 answer
254 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 ...
1 vote
1 answer
138 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 ...
1 vote
1 answer
82 views

Advent of Code Day 8

The task A file similar to the following is provided. ...
1 vote
4 answers
182 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", ...
1 vote
1 answer
113 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 ...
0 votes
1 answer
46 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: ...
1 vote
3 answers
118 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: ...
2 votes
2 answers
161 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. ...
4 votes
1 answer
452 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) ...
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 ...
3 votes
1 answer
52 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 ...
2 votes
2 answers
87 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. ...
3 votes
2 answers
91 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 ...
15 votes
1 answer
493 views

Ruby chess engine gem

This is my first Ruby gem that claims to provide all the rules of the chess game. My goal was to keep this library as simple as possible via OOP principles, and I'd be glad to hear any feedback from ...
4 votes
2 answers
136 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 ...
4 votes
2 answers
587 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 ...
1 vote
1 answer
189 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 (...
1 vote
1 answer
70 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 ...
8 votes
3 answers
6k views

Sums of some array elements

I'm doing an archived MOOC at the moment which introduces Ruby programming. There are some assingments, yet no solutions and since the MOOC is over no one will correct those (+ the forum is down) I'm ...
1 vote
0 answers
79 views

Unpack a flattened hash into Hash/JSON

The following JSON ...
4 votes
1 answer
3k views

Deeply extract all used symbols from a hash of nested symbols in an array

I have a nested hash of symbols like this: { a: { b: :c, d: { e: :f } }, g: :h } I want to build an array that contains all symbols used ...
1 vote
2 answers
93 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 ...
5 votes
3 answers
6k views

Balanced parenthesis in Ruby

I'm solving the "Balanced Parenthesis" problem in Ruby, and I came up with this solution. ...
3 votes
1 answer
100 views

Tentative to transform this scrape script into a class object program

From the last few days I have been studying scraping 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. ...
3 votes
0 answers
58 views

Achieving thread safety in a payment service library

I wrote this code a while ago, which is an excerpt of a payment service library: ...
2 votes
0 answers
102 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 ...
7 votes
3 answers
523 views

Prefix Sum in Ruby, Genomic Range Query from Codility

I'm currently going through some lessons on Codility. I've just spent a couple of hours with GenomicRangeQuery, which is intended to demonstrate the use of prefix sums. The task description is here. ...
1 vote
1 answer
537 views

Caesar Cipher, done in Ruby

It's an assignment from the Odin Project. Here's my implementation: ...
1 vote
1 answer
84 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
2 answers
207 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? ...
0 votes
1 answer
182 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 ...
6 votes
3 answers
4k views

Parsing a string of the form "key1=value1;key2=value2;" into a Hash

I need to parse the following input string into a hash table with the following format: Input: '1001=23;1001B=5;1002=0;1003=5;' Output: ...
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: ...
4 votes
2 answers
116 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-...
0 votes
1 answer
237 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 ...
1 vote
1 answer
155 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 ...
1 vote
2 answers
240 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 ...
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 ...
0 votes
2 answers
239 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 ...
-2 votes
2 answers
47 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
2 3 4 5
33