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

learn more… | top users | synonyms

0
votes
1answer
43 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 ...
2
votes
2answers
157 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 ...
7
votes
3answers
2k views

Help understanding server-side scripting

As far as I understand, there are basically 3 options for doing server-side scripting these days: Using scripting languages that can be directly interpreted/executed by the web server (e.g., PHP and ...
7
votes
6answers
1k views

Is it okay to define a [] method in ruby's NilClass?

Ruby by default does not include the method [] for NilClass For example, to check if foo["bar"] exists when foo may be nil, I have to do: foo = something_that_may_or_may_not_return_nil if foo &&...
3
votes
1answer
157 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,...
0
votes
0answers
68 views

Using Ruby ORM vs DB querying

If one were to set up an API in Sinatra connecting to MongoDB, is it absolutely necessary (or even a "best practise") to define models and use Mongoid (for example) to run DB operations such as User....
1
vote
1answer
175 views

What's the best practice for adding a lot of attributes to a Rails model?

So, I'm building an API wrapper gem that works with Spree's Product model. The API provides extensive customization of the data you send to it. I would like a user of the gem to be able to take ...
0
votes
1answer
44 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, ...
0
votes
0answers
13 views

RubyMotion deployments

I would like to start an application for iOS and Android and I'm considering the option of using RubyMotion for that. I know that you can write Ruby and then deploy to the desired platform. After ...
26
votes
3answers
3k 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
64 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 ...
0
votes
1answer
134 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 ...
1
vote
0answers
60 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 ...
7
votes
3answers
5k views

What can I use instead of Interfaces in Ruby (or any other dynamic language)?

My goal is to define contracts between classes. I like duck typing and all but I'd like also to define an interface between different layers of my application to clearly define which are the method ...
2
votes
0answers
56 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 ...
1
vote
5answers
2k views

Why would you want to use an array, or hash as hash key in ruby?

i'm using Ruby 1.9.3 I figured out that you can use an array, or a hash as hash key in ruby: h = Hash.new h[Array.new] = "Why?" h[Array.new] # Output: "Why?" h[Hash.new] = "It doesn't make sense" ...
8
votes
4answers
206 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
vote
1answer
96 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 ...
1
vote
2answers
1k views

How do I read API documentation? [closed]

I've been trying to read through the RoR API to try to learn things that the tutorial missed, and I haven't been able to follow it at all. The only time I've read documentation was when I needed to ...
2
votes
3answers
179 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 ...
37
votes
9answers
8k views

Explanation on how “Tell, Don't Ask” is considered good OO

This blogpost was posted on Hacker News with several upvotes. Coming from C++, most of these examples seem to go against what I've been taught. Such as example #2: Bad: def check_for_overheating(...
3
votes
1answer
193 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. ...
3
votes
2answers
99 views

Is a guardfile part of the private developers environment or the public OSS project?

Let us say I have an open source project on github. Now I wish to include tools required to develop the project so others can easily contribute. It is hard for me to tell when these tools should be ...
9
votes
1answer
228 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
142 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
94 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' ... ...
5
votes
4answers
310 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 !...
6
votes
2answers
8k views

Why do people suggest not to use instance variable for views in Ruby on Rails

Why do I hear that it is not good to share instance variables between controllers and views. I kind of like it because I can see immediately via the @ that something is coming from the controller. I ...
1
vote
1answer
933 views

ruby-idiomatic hashes vs arrays

So I am still fairly new to ruby, though I have noticed that it is very hard to create 2d-array and that hashes seem to be more of the go to data structure than arrays. I was wondering why the Ruby ...
0
votes
1answer
79 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 ...
5
votes
2answers
497 views

How are scripting languages compiled?

I know the term "scripting languages" is just a subset of programming languages, but I want to refer to programming languages such as Python and Ruby among others. First of all, why don't we need a ...
2
votes
5answers
336 views

What happened to VM based deployments?

Watched some MountainWest RubyConf 2014 talks and noticed an interesting theme. Many dynamic programming environments back in the old days used to be self-contained VM images, e.g. SmallTalk, GemStone/...
0
votes
0answers
67 views

Add-on hot deployable modules for Akka actors?

I'm trying to build a small spray io - akka distributed application targeted towards smaller devices like the Raspberry Pi and BeagleBone Black. The aim is to be able to talk to other devices that ...
1
vote
0answers
66 views

Where did the tradition of new releases on Christmas Day start? [closed]

Perl 6 is being released on Christmas Day this year. I'm familiar with Ruby having a history of releases on Christmas Day, going back as far as Ruby 1.0 in 1996 if not further. However, a quick scan ...
1
vote
0answers
117 views

Terminology - Difference between thread and process and how they manage DB connections

I've been working more with concurrency in Ruby recently, and I keep seeing various articles using "threads" and "process" interchangeably. What are the actual definitions of these terms? Is a ...
4
votes
2answers
6k views

Ruby Sinatra best practices for project structure [closed]

Many people praise Sinatra's ability to create simple projects in a single file. This is great and all but what if I want to use Sinatra for slightly larger project? I'm fairly new to Ruby as a ...
3
votes
1answer
372 views

Android App with Ruby Backend Server

I'm working on a personal project to help me branch out and learn some new/different technologies. I'm a .NET programmer but I want to learn Ruby and how to develop Android apps. I have developed ...
1
vote
4answers
697 views

What is the “correct” way to store functions in a database?

Note: Yes, I know that storing functions in databases should be punishable by law. We are developing a financial web application using PostgreSQL, Sinatra and AngularJS. As you may have guessed, a ...
1
vote
2answers
690 views

Is the time complexity of a while loop with three pointers different than 3 nested for loops?

This program (written in ruby) finds the largest 3 numbers in an array (without sorting the array). It has a while loop with three pointers. My fist instinct, since there is only one loop is to say ...
0
votes
1answer
272 views

Best way to design a database interface [duplicate]

This is my situation I have a website, mobile client and desktop client. They can all pretty much do the same operations (website might be able to do more now but in the future they might have the ...
1
vote
0answers
160 views

Securing a private API used by an iOS App

I have an app that uses an API server and I do not want to have anything other than it to be able to use that API. I know this isn't totally possible, but I want to do what I can. I don't think my ...
1
vote
4answers
591 views

Is there any situation when there's no alternative to instanceof?

It seems to me that instanceof comes from the land of functional programming and is a watered down version of pattern matching and that the OO altenative to it should be dynamic dispatching. In OO ...
-2
votes
1answer
258 views

Why is Ruby's interpreter so small? [closed]

I noticed that the filesize of Ruby's interpreter seems suspiciously small. I would have expected /bin/dash to be the smallest of all, but is 20x larger than Ruby: Interpreter Bytes -----------...
10
votes
8answers
3k views

How do I design a subclass whose method contradicts its superclass? [duplicate]

How do I design a subclass whose method contradicts its superclass? Let's say we have this example: # Example 1 class Scissor def right_handed? true end end class LeftHandedScissor < ...
1
vote
3answers
642 views

How can I rank teams based off of head to head wins/losses

I'm trying to write an algorithm (specifically in Ruby) that will rank teams based on their record against each other. If a team A and team B have won the same amount of games against each other, then ...
32
votes
5answers
15k views

Return random `list` item by its `weight`

I have, for example, this table +-----------------+ | fruit | weight | +-----------------+ | apple | 4 | | orange | 2 | | lemon | 1 | +-----------------+ I need to return random ...
0
votes
3answers
174 views

Would it be possible to create a language similar to Ruby/Python with static typing that had the speed/memory usage of a compiled C program? [closed]

One of the main drawbacks of Ruby/Python is performance. I understand that they are interpreted and C is compiled. (And there are things like JRuby which do JIT compilation with Ruby). But they never ...
5
votes
3answers
730 views

What can procs and lambdas do that functions can't in ruby

I've been working in Ruby for the last couple weeks, and I've come to the subject of procs, lambdas and blocks. After reading a fair share of examples from a variety of sources, I don't how they're ...
8
votes
4answers
1k views

PHP and Ruby: how to leverage both? and, is it worth it? [closed]

As you might have noticed from the title, this is not a "PHP or Ruby", or a "PHP vs. Ruby" question. This is a question on how to leverage PHP + Ruby in the same business. I myself am a PHP developer,...
9
votes
4answers
569 views

Is Non-Deterministic Resource-Management a Leaky Abstraction?

From what I can see, there are two pervasive forms of resource-management: deterministic destruction and explicit. Examples of the former would be C++ destructors and smart pointers or Perl's DESTROY ...