Skip to main content

All Questions

Tagged with
0 votes
2 answers
308 views

Refactoring Rails scope method CASE-WHEN-THEN-ELSE-END in MySQL

I'm using MySQL and upgrading my application to Rails 7. In doing so, I've to refactor some order-related queries in my scope methods. Before of Rails 7 I was using the following scope method (call it ...
Backo's user avatar
  • 18.9k
0 votes
2 answers
150 views

DRY way of assigning new object's values from an existing object's values

I created a class method that is called when a new object is created and copied from an old existing object. However, I only want to copy some of the values. Is there some sort of Ruby shorthand I can ...
ra-11's user avatar
  • 13
0 votes
2 answers
188 views

How can I replace an instance variable with another one conditionally?

I am assigning values to an instance variable of a class. The scenario is that I need to call a function at least three times, and each call requires an answer to be stored in another instance ...
Muhammad Fahad's user avatar
0 votes
1 answer
78 views

Refactoring nasty rails controller

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 rails_best_practices to ...
Daniel's user avatar
  • 191
-3 votes
1 answer
100 views

A better method to iterate over an array and object attributes? [closed]

(Edit:Now i just use ChatGPT for coding stuff... 1000x better than SO policy and moderators) I found a solution that works, but i did some heavy copy/paste of blocks and there is only the params of ...
AnnABlue's user avatar
  • 151
0 votes
1 answer
328 views

Set a Ruby class variable, then use it in a class method. HTTParty

I am trying to create an API wrapper for recharge (A Shopify subscription service), I am using the HTTParty gem module RechargeAPI require 'httparty' BASE_URI = 'https://api.rechargeapps.com' ...
Artyrcheek's user avatar
0 votes
0 answers
50 views

Refactor Rails controller

I am trying to achieve this feature: Sent texts out to new authors. It enables admin users to when authors published their first article in a specified timeframe, Compose and send out emails to ...
Mag's user avatar
  • 49
2 votes
1 answer
76 views

Stuck with refactoring classes on ruby on rails 5

I have a class with different methods but on these methods i need to do a check on the access token before doing some calls class SomeClass def initialize @client = SomeModule::Client.new ...
Dante's user avatar
  • 120
1 vote
1 answer
1k views

Metrics/ParameterLists: Method has too many optional parameters. [4/3] Ruby

All params are required class Library attr_accessor :authors, :books, :orders, :readers def initialize(authors = [], books = [], orders = [], readers = []) @books = books @...
Warden's user avatar
  • 109
1 vote
1 answer
231 views

Metrics/AbcSize: Assignment Branch Condition size for fill_arrays is too high. [<9, 21, 0> 22.85/17]

I need to generate random data with ffaker and have no clue how to fix abcsize here Here is what i had class Library attr_accessor :authors, :books, :orders, :readers def initialize(authors = [], ...
Warden's user avatar
  • 109
1 vote
1 answer
202 views

How to pass array as individual arguments in ruby?

I am trying to think of a more elegant way to pass elements of an array as individual arguments to a method. So far, I have the following code: def fetch_data(keywords) Product.where("name ...
ninja_nugget's user avatar
0 votes
1 answer
267 views

Ruby on rails, Rubocop refactoring

Offenses: app/controllers/tasks_controller.rb:12:3: C: Metrics/AbcSize: Assignment Branch Condition size for create is too high. [<3, 19, 1> 19.26/17] def create ... app/controllers/...
Warden's user avatar
  • 109
1 vote
1 answer
217 views

Minesweeper game board | ruby

I have written a code for the drawing board for the minesweeper game, can anyone help me to refactor this code more. Please find my code below def draw(height, width, mines) board = Array.new(height)...
Avinash Kumar Singh's user avatar
0 votes
2 answers
42 views

Creational adapter

I have a lot of code like this additional_params = { date_issued: pending.present? ? pending.date_issued : Time.current, gift_status: status, date_played: status == "Opened" ? Chronic....
megas's user avatar
  • 21.8k
1 vote
2 answers
49 views

Is there a way to refactor this without using 3 collectors to combine strings?

I'm trying to refactor the following: def method_name array = ["abcdef", "ghijkl", "mnopqr"] collector1 = "" collector2 = "" ...
booswerd's user avatar

15 30 50 per page
1
2 3 4 5
30