Questions tagged [ruby]
Ruby is a multi-platform, open-source, dynamic, object-oriented, interpreted language created by Yukihiro Matsumoto (Matz) in 1993.
1,612 questions
3
votes
1
answer
72
views
Ruby Array#own_uniq method
I have implemented my own version of Ruby's Array uniq-method (Ruby docs - Class array) as a monkey patch on Array.
Method-impl.:
...
6
votes
2
answers
459
views
(Codewars) Goldbach's Conjecture (by @rsalgado) in Ruby
Link to kata: linkRank: 6 kyuKata author: @rsalgado
I have been recently learning Ruby-lang and have been attempting to solve the following kata from Codewars involving Goldbach's Conjecture:
...
4
votes
1
answer
212
views
Fetching data from a REST-API then converting to CSV
I like to have a script which fetches data from a REST-API then writes the data into a CSV file.
Here's what I've got so far (prototype, using a publicly accessible dummy-API):
...
5
votes
3
answers
135
views
Ruby: Check for Palindrome (as Monkey-Patch on String-class)
I have written a method, which checks for Palindrome and attached it to the String-class.
Here's the code:
...
2
votes
1
answer
85
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 ...
1
vote
1
answer
124
views
Advent of Code Day 8
The task
A file similar to the following is provided.
...
3
votes
3
answers
177
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:
...
1
vote
4
answers
287
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", ...
6
votes
1
answer
513
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) ...
3
votes
1
answer
79
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 ...
1
vote
1
answer
218
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 (...
4
votes
2
answers
628
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 ...
4
votes
2
answers
173
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 ...
1
vote
1
answer
146
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 ...
1
vote
1
answer
196
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 ...
4
votes
1
answer
115
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
1
answer
214
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
2
answers
73
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
...
0
votes
1
answer
480
views
Ruby: Chaining methods vs methods with arguments?
I started with the following module:
...
3
votes
1
answer
248
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:
...
2
votes
2
answers
209
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
2
answers
280
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
0
answers
247
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
}
]
...
4
votes
1
answer
124
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
1
answer
107
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 ...