Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [ruby]

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

-4
votes
0answers
16 views

Initiate variables with explicit types in Crystal

After skimming through the tutorial at www.crystal-Lang.org, I understand most of the basics but I’m having trouble grasping types. Like everything else they seem to be somewhere between Ruby’s (...
-1
votes
0answers
31 views

Writing code compatible with BOTH Ruby and Crystal

I know both languages are syntactically similar so i'm a little interested in using both in the same source file. Right now, unfortunately, I only have an Android phone with Ruby installed in Termux. ...
1
vote
1answer
35 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
587 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
146 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 ...
1
vote
1answer
39 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
124 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 ...
0
votes
0answers
88 views

Better pattern to ensure single responsibility

What's a better pattern here to ensure that my methods follow the single responsibility principle. I have a pretty DRY controller, that I think makes sense and is concise. Here is my controller: ...
1
vote
0answers
117 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
126 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 ...
14
votes
6answers
4k 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
54 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
68 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 ...
1
vote
0answers
47 views

How should I handle private key in decryption worker?

I own the development of a Sidekiq worker that decrypts thousands of gpg encrypted CSVs and loads them into the database. While not necessary, I'm using a gem to interact with the gpg/GnuPG binary. ...
2
votes
1answer
132 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
419 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. ...
-1
votes
1answer
256 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
154 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
318 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 ...
1
vote
0answers
67 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
119 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
151 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
38 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", ...
7
votes
2answers
338 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
233 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
139 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
43 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
893 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
83 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
97 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
340 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 ...
12
votes
3answers
1k views

Why did Ruby creator had 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 creators use the concept of symbols in the language? I ask this ...
1
vote
3answers
243 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
145 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
99 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 ...
34
votes
3answers
6k 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
57 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
166 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 ...
3
votes
0answers
791 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 ...
8
votes
4answers
263 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 ...
2
votes
3answers
199 views

Using multiple languages

I currently have a website running PHP laravel. We came to a point where we want to add a user-backend -- where users sign-up and can access functions when logging in. My question is; Is it possible ...
4
votes
1answer
954 views

How to implement a (truly) global variable in a Rails app

How can I best implement a global counter in a Rails API app? (A central component in a system with several.) Basically I have a transaction id I need to increment and roll over past a maximum value. ...
1
vote
1answer
269 views

Ruby: Abusing mixin

I'm currently working with some code that IMO has abused ruby's mixin features. Given that I'm new to ruby, I wonder if MO in IMO is correct or not. My primary question is what makes more sense (and ...
5
votes
1answer
779 views

How do I go about setting up my Sinatra REST API on a server?

I'm an iOS developer primarily. In building my current app, I needed a server that would have a REST API with a couple of GET requests. I spent a little time learning Ruby, and landed on using Sinatra,...
9
votes
1answer
278 views

Python's join seems to focus not on the items to join, but on the symbol, as compared to Ruby or Smalltalk, for a design reason?

I thought one of the cornerstone of OOP is that, we have objects, which are the items we are interested in dealing with, and then we send messages to them. So it may seem natural that, I have a ...
6
votes
1answer
490 views

Testing procedural code

TL;DR. Writing procedural code within a DB transaction. How can I improve design of the code so it's better testable? In my application I have a service object that perform multiple things within the ...
0
votes
2answers
352 views

Using symbols instead of strings in conditions

I usually have if/else conditions which involves comparing values with a constant string. Is it really advantageous to use symbols in such cases or use string. For eg. if status == 'submitted' ... ...
9
votes
4answers
24k views

Ruby: if variable vs if variable.nil?

I'm new to Ruby and I was surprised when I found out that all objects are true apart from nil and false. Even 0 is true. A nice thing about that property of the language is that you can write: if !...
0
votes
1answer
129 views

Does extending a ruby class violate the LSP?

I am reading about SOLID principles. In Ruby tutorials and code samples, I often see subclass extensions like: class House attr_reader :items end class Room < House attr_reader :chair end p ...
0
votes
1answer
605 views

Ruby best practices for Data Access layers

I'm starting my way into Ruby development and have some questions that I hope you can give your best opinion to better design some command line applications I'm developing. What are the best patterns ...