Skip to main content

Questions tagged [ruby]

Questions about Ruby, dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features.

Filter by
Sorted by
Tagged with
4 votes
1 answer
370 views

I'm reading the book The Secret Life of Programs by Jonathan E. Steinhart. In it, he mentions in passing: many consider the handling of whitespace in Ruby to be a replay of of a mistake in the ...
tsvallender's user avatar
-1 votes
1 answer
892 views

I'm working a project where I found another developer wrote a method as you see it below. How would I clean those IF statements and refactor this method. Also is it ok ti set a variable to nil ? def ...
egyamado's user avatar
  • 117
6 votes
3 answers
4k views

Currently working on a Ruby-on-Rails codebase, testing is done with Rspec. We use BuildKite to run tests. We are in a situation where sometimes tests will fail, and upon a retry or two, pass. AKA, we ...
Julien Chien's user avatar
1 vote
1 answer
258 views

I am building a simple application built in Rails that allows the client to connect to a third party api to sync customer data. The customer inputs their username and password and my application ...
Joe Ainsworth's user avatar
-1 votes
1 answer
786 views

I am building the initial set of unit tests for my team's legacy API client system. We have been writing integration tests, but have no unit tests. It's a Sinatra server that accepts requests from our ...
Eric's user avatar
  • 107
2 votes
2 answers
174 views

Maybe that's simple, but it confuses me. I have such a code now: describe VarnishLogExaminer::Entry do let(:entry) do file_string = File.read('./spec/assets/varnish_example.xml') ...
Karol Selak's user avatar
0 votes
0 answers
110 views

We have several Rails applications using the same ActiveRecord, Book. For simplicity let us assume we have only these two: BookWarehouseApp (that deals how new book are added, or other inventory ...
sunless's user avatar
  • 151
-4 votes
1 answer
198 views

How to tell if we have unused require expressions? For example: require 'colorize' require_relative './helpers' puts 'Hello, world!' This is a very simple example but there can be larger/complex ...
MauricioRobayo's user avatar
1 vote
0 answers
34 views

I'm trying to figure out the best way to "partially" use the validates_uniqueness_of validator for a particular case of problem. Let's say I have a Book class with multiple comments, with the Comment ...
dtynan's user avatar
  • 19
-1 votes
1 answer
91 views

I am writing an implementation of a binary search tree and in doing this I need a method that splits an array in two. I am unsure where it is appropriate to place this method. What I mean by "where ...
fossegrim's user avatar
  • 123
1 vote
1 answer
363 views

I built an audio processing web app using Rails. The user uploads a song to the website. The song is then decomposed into individual elements and then modified and recombined. I am using a an open ...
musicjackx's user avatar
1 vote
2 answers
971 views

Maybe that's simple, but I'm a little confused. I have such a Ruby code: def my_function(found_objects) # ... if found_objects.second return CoreObjectFactory.get_object(found_objects.second,...
Karol Selak's user avatar
0 votes
0 answers
62 views

I am working on a little project which essentially allows me as the administrator to upload new products to the app (each product would be a video explaining product) which would have its own specific ...
justlivinglife's user avatar
9 votes
2 answers
491 views

I am working on a project where clients are able to create objects in a database. Each of these objects has a description string that describes the object. Let's assume we are looking at an object ...
wsg's user avatar
  • 199
1 vote
1 answer
101 views

I have a class that looks like this: class MyClass # takes an array of actions def initialize(actions) @actions = actions end def act @actions.each {|a| a.do} end end class ...
ivanibash's user avatar
  • 143
2 votes
1 answer
244 views

I am a beginner in Ruby and I am trying to wrap my head around symbols. Would you say that my current understanding, summarized in the following (oversimplified) definition, is true for most purposes? ...
FlatronL1917's user avatar
9 votes
4 answers
1k views

I recently watched "All the Little Things" from RailsConf 2014. During this talk, Sandi Metz refactors a function that includes a large nested if-statement: def tick if @name != 'Aged Brie' &&...
user200783's user avatar
-1 votes
2 answers
669 views

I work for a Rails SaaS platform that was recently acquired by a primarily Microsoft shop. They are pushing the issue we need to rewrite the entire application in .NET. It's very clear they know ...
Deekor's user avatar
  • 507
2 votes
2 answers
150 views

I'm currently trying to figure out how to solve following problem: I have a model called Post that has, among other attributes, link_1_text, link_1_url, link_2_text and link_2_url for users to add ...
Klaus Turbo's user avatar
3 votes
3 answers
272 views

I'm trying to figure out the complexities of these two functions that I've written but could not understand.def First, I thought it is supposed be O(N). But it is not clear how many times the loop ...
aravvn's user avatar
  • 139
5 votes
2 answers
762 views

Consider the following minimal example: class SomeException < StandardError end class Example @@logger = Logger.new @@failure_count = 0 def do_a_thing(array) raise SomeException unless ...
Mikey T.K.'s user avatar
2 votes
1 answer
738 views

I need to make some get/post requests to a website that I have credential to log in. I plan to do this with Ruby and Net::Http. As I'm new to this kind of experience, I'm struggling with the fact that ...
Pedro Gabriel Lima's user avatar
19 votes
6 answers
9k views

Context I recently got interested into producing better formatted code. And by better I mean "following rules endorsed by enough people to consider it a good practice" (since there will never be one ...
Sudiukil's user avatar
  • 199
0 votes
0 answers
136 views

According to the Single Responsibility Pattern (SRP) a method or class should have one responsibility. I have read a couple of sources and viewed some videos and I would like to understand it by ...
030's user avatar
  • 548
3 votes
1 answer
98 views

I am writing a bot for Matrix using Ruby which allows users to subscribe to RSS feeds and when a new item shows up on the feed it gets sent to the room. The problem I have come up against is how do I ...
Qwertie's user avatar
  • 506
2 votes
1 answer
429 views

I'm very new at writing Cucumber tests. I'm writing Ruby helper functions to assist Cucumber step definitions. Should there be a separate set of tests to test my helper functions i.e. unit tests? The ...
QCFia's user avatar
  • 31
1 vote
2 answers
2k views

When applying DDD principles in Ruby, I feel that Active Record pattern ends up polluting the domain model, while I'm not sure how to implement JSON deserialization without breaking encapsulation. ...
FedericoG's user avatar
1 vote
1 answer
1k views

For instance, if I wanted to make a game which used a Python main file, but have another file with Ruby methods on it, how would I call those methods individually? Secondly, how could I make a Ruby ...
sirsnow's user avatar
  • 41
0 votes
2 answers
957 views

I understand that objects external to an aggregate shouldn't hold references to entities and value objects belonging to the aggregate. My question if this also applies to the Application Service that ...
FedericoG's user avatar
0 votes
1 answer
1k views

It seems to me that Ruby hashes would be a good option to implement the Data Transfer Objects that the Application Services receive from the client code as commands and queries requests. For ...
FedericoG's user avatar
2 votes
2 answers
418 views

We have a persistence backed object, and it has a version field in the database. Assume there's lots of unrelated code in this class. # # We're branching on this "version" field, and we return one # ...
Rorshark's user avatar
  • 112
0 votes
1 answer
172 views

I'm new to actors and just playing around in ruby using Celluloid. I have this code below module Enumerable # Simple parallel map using Celluloid::Futures def pmap(&block) futures = map { ...
Grimbox's user avatar
  • 377
0 votes
1 answer
302 views

How would one implement an actor-based concurrent language in ruby? My thought is that only the correct way of creating programs is using actors, but I'm not entirely sure on how this could be done, ...
Grimbox's user avatar
  • 377
0 votes
1 answer
61 views

My client has a nodejs SDK that fetches entries using a client that makes http requests. Their api looks like this: var Query = Client.ContentType('blog').Query(); Query .where("title", ...
Amit Erandole's user avatar
6 votes
2 answers
713 views

I'm developing a Ruby on Rails app. The app contains a service wrapping an external REST API, called from a controller, with several possible error states. The current implementation returns the ...
jacwah's user avatar
  • 395
2 votes
1 answer
914 views

I have a big list of email addresses and I want to find out which of those are duplicates. How to define "duplicate" is exactly what I'm posting about here. I know from experience that with Gmail, ...
max pleaner's user avatar
1 vote
1 answer
290 views

I was recently debugging a bit of code where the previous implementation looked something like this: # controller for group/customers def index @customers = current_user.available_customers(param[:...
Jen's user avatar
  • 693
4 votes
0 answers
71 views

An interesting design choice/discussion has cropped up in code review, and I would like to understand more about proposed solutions. The original review includes re-factoring of a messy piece of code ...
Neil Slater's user avatar
6 votes
1 answer
5k views

In this question, I'll use a ruby example, but I think it is a general question. According to the most popular Ruby's test framework (RSpec), mocking any instance of a class (allow_any_instance_of) ...
Rodrigo's user avatar
  • 1,077
-1 votes
1 answer
105 views

Here is the situation, I wish to use the last programming language of ruby, python and some more on my development machine, but the server where it will be is not last version of that programming ...
aurelien's user avatar
  • 157
1 vote
1 answer
110 views

In traditional Rail app, we need to deal with controller/model/action and has a view that generate HTML output. Now There are many JS framework like backbone/react that allow us to code client side ...
Yoga's user avatar
  • 325
1 vote
0 answers
573 views

To clear some potential confusion, let me start with the following statements As far as I understand, inheritance is mostly about dynamic dispatch. I understand how virtual pointer table based ...
Ianis Vasilev's user avatar
18 votes
3 answers
3k views

tl;dr: Would there be a language-agnostic definition of Symbols and a reason to have them in other languages? So, why did the Ruby creator use the concept of symbols in the language? I ask this ...
Yuri Ghensev's user avatar
1 vote
3 answers
276 views

I am currently working with a contractor who's code instantiates a large number of objects upfront at the start of the application. This application is written in ruby, but I wonder how something ...
Jake S's user avatar
  • 19
0 votes
1 answer
211 views

I’m creating an app that allows users to post, sell, and purchase items. Every item has a count integer attribute that is set by the initial user and which is reduced by n with each purchase. When ...
calyxofheld's user avatar
0 votes
1 answer
158 views

I'm very new to ruby. I have to code in ruby at work and a coworker gave me some tests he wrote in ruby. I have some difficulties to understand a line he wrote. We have a class like this: class Port ...
user3314570's user avatar
44 votes
3 answers
15k views

Let's say I have a function (written in Ruby, but should be understandable by everyone): def am_I_old_enough?(name = 'filip') person = Person::API.new(name) if person.male? return person....
Filip Bartuzi's user avatar
0 votes
1 answer
79 views

In Ruby, is there a standard class or gem to work with dates that can be - but are not required to be - historical in nature? The dates have precision (to the nearest million years, decade, century, ...
Bradley Marques's user avatar
1 vote
0 answers
195 views

I have been working on a application that up until now has been pure Node. However I am concerned about performance and overhead since the application performs a lot of file system operations (Copy ...
Taylor Ackley's user avatar
4 votes
1 answer
2k views

I've got a Rails eCommerce project communicating with an iOS app. The iOS app receives JSON data from the Rails back-end, but there's also HTML rendering when a user comes to the project from his ...
Laurent's user avatar
  • 141

1
2 3 4 5 6