Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
2 votes
1 answer
64 views

Ruby setter-methods: Is the equal-character (=) a convention or functionality?

Taken this class as a example: class House def initialize(color, size) @color = color @size = size end def color @color end # Is the = part of the syntax or a convention? def ...
cluster1's user avatar
  • 5,468
0 votes
0 answers
47 views

How to extend an object in Ruby? [duplicate]

Say, I have an object that replies to .hello method. Now, I want to create another object that will reply to both hello (and all other methods of the original object) and bye methods. Something like ...
yegor256's user avatar
  • 104k
0 votes
1 answer
67 views

Ruby OOP classes interaction: Which way to update instance variables?

I have 2 classes: Game and Player. This is a Tic-tac-toe game. class Game attr_accessor :player_1, :player_2, :numbers, :board def initialize(player_1, player_2) @player_1 = player_1 ...
Ong K.S's user avatar
  • 287
2 votes
1 answer
86 views

Ruby class constructor using `()` rather than `.new()`

Please do not ask me "why do you want to do this?" I'm just exploring the nooks and crannies of Ruby, with no specific goals in mind. Some Ruby classes can be instantiated with just ...
RoUS's user avatar
  • 1,980
0 votes
0 answers
42 views

Hangman Ruby Game - Why Does the Winning Message Delay and Saved Game Prompt Repeat?

I am developing a Hangman game as part of the Odin Project curriculum (https://www.theodinproject.com/lessons/ruby-hangman). The game utilizes a dictionary file (https://raw.githubusercontent.com/...
Shahid Haris's user avatar
-2 votes
1 answer
41 views

Some methods in my Ruby class appear to be private by default? Even though they are regular methods within the class [closed]

class ProcessTrip < MetroCardClassMethods attr_accessor :travel_history, :station, :destination def initialize end def update_balace_aumount(balance_details,trip_to,trip_complete) ...
Moin Ahmed's user avatar
0 votes
2 answers
49 views

Accessing instance method of a different class with current object

From the book Practical Object-Oriented Design in Ruby, by Sandi Metz: class Gear attr_reader :chainring, :cog, :rim, :tire def initialize(chainring, cog, rim, tire) @chainring = chainring @cog =...
current_user's user avatar
  • 1,202
0 votes
2 answers
335 views

coding challenge solution with a hidden bug

Recently I took a coding challenge on turing. The question was : You will be given a string list(ops) as input. If its an integer you have to keep a record of it If it's a character 'C', you have to ...
coder2023's user avatar
1 vote
1 answer
46 views

Handling non created object in ruby

I have created a class using the singleton design pattern. The main objective of the class is to create an email id only when the email is valid. If the email is not valid it will not create an object....
S_coderX451's user avatar
3 votes
1 answer
143 views

Ruby: Is it ok for a method to return an object of different types?

Is it a good idea to return an object whose type changes depending on the method’s inner logic? E.g.: class Error attr_reader :details def initialize(details) @details = details end end ...
mate's user avatar
  • 126
0 votes
0 answers
50 views

If my ManageMonster Class have bloated parser / input checker should I move it to a new class MngMonsterParser? (OOP design question)

Say for example I have a microservice where I need a class where I can manage a monster from another service, like level it up, update its status (sick, hungry and etc) and take a picture with it(save ...
joyfuljoy's user avatar
1 vote
2 answers
42 views

How do I keep track of automatically instanced unassigned objects in basic Ruby?

I am trying to build a mastermind game, and I am hoping to have my code instance its own objects containing information about the place and color of the step in the passcode. This is so I can vary the ...
coveredinclover's user avatar
0 votes
1 answer
75 views

Rails Job to Merge Records With Similar Phone Numbers

I have a Postgres database with tens of thousands of User records, each having a phone number. However, there are many duplicate Users with the same phone number, but one record might be missing the ...
ra-11's user avatar
  • 13
2 votes
1 answer
41 views

Nil class for objects in a collision detection test

I ran into a problem while testing for a collision detection system. For the sake of visualization, you can think of the overall structure of the code as Main Class =>Class(ship, shell, enemy), the ...
Simplylmk's user avatar
  • 267
1 vote
1 answer
59 views

Problem adding Class Node object to array

I am looking for the below code to be able to print out and return my final_path array from my #find_knight_path function. It runs just fine with the puts lines I have, but as soon as I try to puts ...
Cali_Ranger's user avatar

15 30 50 per page
1
2 3 4 5
51