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
0
votes
0answers
10 views

Idiomatic Ruby if/else in a Sinatra route [migrated]

Apologies if this question doesn't fit the format here, seemed more appropriate here than SO due to the more nebulous nature of the question. Think mini tinyURL clone: POST to service to save the url +...
1
vote
0answers
31 views

Tracking flakey tests in Ruby on Rails / Rspec - is there a way to do this?

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 ...
1
vote
1answer
39 views

Best way to renew OAuth token before expiry

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 ...
0
votes
0answers
34 views

How to create input data for unit tests for an API client?

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 ...
2
votes
2answers
117 views

Is it a good idea to violate the DRY rule for keeping the action in proper context?

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') ...
0
votes
0answers
22 views

Sharing ActiveRecord class between two Rails app with gem

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 ...
-4
votes
1answer
70 views

How to identify require expressions that are not needed?

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 ...
1
vote
0answers
16 views

Best RoR pattern for special instances of a subclass

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 ...
-3
votes
1answer
57 views

Where is it appropriate to implement the split_array method

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 ...
1
vote
1answer
105 views

How to efficiently process CPU intensive tasks on the server in the background

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 ...
1
vote
2answers
271 views

What is the cleanest way of writing a function with conditional statement with many returning options?

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,...
0
votes
0answers
26 views

Ruby on Rails newbie question, regarding general design for models/controlers for feedback app/ my thinking

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 ...
8
votes
2answers
266 views

Best practices for internationalization: composed sentences?

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 ...
1
vote
1answer
63 views

What is a good way of satisfying open/closed principle in this case

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 ...
2
votes
1answer
162 views

Symbol definition in Ruby

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? ...
9
votes
4answers
838 views

Refactoring - is it appropriate to simply rewrite code, as long as all tests pass?

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' &&...
-1
votes
2answers
430 views

Argument for staying on Rails instead of migrating to .net MVC?

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 ...
2
votes
2answers
78 views

Best practice to add polymorphic attachments to a post

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 ...
2
votes
3answers
162 views

What is the complexity of find and checking prime numbers?

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 ...
4
votes
2answers
366 views

Ruby: Exceptions for flow control inside an .each block

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 ...
2
votes
1answer
243 views

How to HTTP request to a website that uses robot verification

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 ...
15
votes
6answers
6k views

One-liners vs. readability: when to stop reducing code? [closed]

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 ...
0
votes
0answers
122 views

Understanding Single Responsibility Pattern (SRP) [duplicate]

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 ...
3
votes
1answer
72 views

How do deal with an IM bot that needs to run minutely tasks while also waiting for commands

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 ...
2
votes
1answer
196 views

Should I unit test my Cucumber helper functions/classes?

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 ...
0
votes
2answers
886 views

DDD: How to avoid breaking encapsulation and leaking technical concerns to the domain during model rehydration?

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. ...
0
votes
1answer
614 views

How would I integrate python code into Ruby code?

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 ...
0
votes
2answers
435 views

Should the Application Service in DDD use references to non-root entities and value objects inside an aggregate?

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 ...
0
votes
1answer
552 views

Is it advisable to use hashes as DTOs in Ruby when applying DDD?

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 ...
0
votes
1answer
107 views

How to better factor classes that switch on type code

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 # ...
0
votes
1answer
135 views

Celluloid actors parallel work slow?

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 { ...
0
votes
1answer
199 views

Implement an actor-based concurrent language in ruby?

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, ...
0
votes
1answer
39 views

Creating a better translation for a node.js api to ruby

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", ...
6
votes
2answers
469 views

How do I create idiomatic error interfaces in Ruby?

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 ...
2
votes
1answer
533 views

Finding duplicate email addresses. How heavily should I normalize them?

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, ...
1
vote
1answer
180 views

Type Conversions in a dynamically typed language - Where should the conversion happen?

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[:...
2
votes
0answers
45 views

Component needs to invoke class methods and instance methods (via ORM), how to structure

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 ...
4
votes
1answer
2k views

Testing: why expect_any_instance_of is considered a design smell?

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) ...
-1
votes
1answer
85 views

Can I use python 3.5.2 on my machine for development if the client is 3.4?

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 ...
1
vote
1answer
99 views

API oriented web app for both public and private consumptions in Ruby

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 ...
1
vote
0answers
444 views

Conceptual similarity between Ruby's and JavaScript's inheritance models

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 ...
15
votes
3answers
2k views

Why did Ruby creator chose to use the concept of Symbols?

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 ...
1
vote
3answers
247 views

When is it ok to instantiate all of my objects upfront?

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 ...
0
votes
1answer
172 views

database architecture for ecommerce app

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 ...
0
votes
1answer
112 views

Name of a symbol in ruby

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 ...
38
votes
3answers
9k views

Are integration tests meant to repeat all unit tests?

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....
0
votes
1answer
60 views

Historic (and prehistoric) dates in Ruby [closed]

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, ...
1
vote
0answers
175 views

Choosing Between Ruby and Python for a FS Microservice Backend in Node App [closed]

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 ...
4
votes
1answer
1k views

Best way to build a JSON API coupled with HTML views in a Rails project

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 ...
7
votes
4answers
287 views

When in your language classes are objects too, does the Liskov substitution principle apply to their interfaces?

According to Wikipedia the Liskov substitution principle states that objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program ...

1
2 3 4 5 6