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

3
votes
1answer
2k views

What is a closure and how is it implemented in Ruby?

In the context of the Ruby programming language, what is a closure and when do you use one? What are the uses for it in Rails?
0
votes
3answers
662 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" ...
0
votes
0answers
77 views

RGB => HSL => hue range name conversion algorithm off by positive 60 degrees [migrated]

Background For practice (in ruby) I am implementing some color conversion algorithms. I have attempted to convert pseudocode avilable on EasyRGB.com to Ruby. The conversion seems to be working fine. ...
0
votes
1answer
179 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 ...
0
votes
1answer
137 views

How does the consumer-producer solution work?

I'm only a beginner, and my book doesn't cover this subject. I have researched my problem and found that an implementation of the consumer-producer pattern is the ideal solution, and have Googled it, ...
1
vote
2answers
140 views

In Ruby, change global in thread safe block

In Ruby, I have a use case for a few common configuration options, e.g. NOOP, TRACE, SILENT. Right now I am using local vars instead of globals and passing them around all over the place and it's a ...
3
votes
0answers
49 views

Is this code solid? If it's not why not? And how should the dependencies be managed? [closed]

I am very interested in following the SOLID principles of writing code, but for the life of me I consistently run into more questions than answers. One of the questions I have now related to the code ...
8
votes
2answers
317 views

Why don't Python and Ruby make a distinction between declaring and assigning a value to variables?

Two of the most popular dynamically typed scripting languages, Python and Ruby, do not make a distinction in syntax between the declaration of a variable and assignation of a value to it. That is in ...
0
votes
1answer
136 views

How can I write these services using SOLID and keep them easy to test?

I am trying to write a couple of classes using SOLID principles and having some trouble. The problem is quite simple. I have an application that tracks leads. Leads are created when events are raised ...
1
vote
1answer
49 views

How do rails project know about rake tasks from other repositories

We have a rake task called db:sanity_check which exists in a 'core' repo. Other repositories that we have also show this rake task. But they do not define the rake task. It 'comes' from core' How ...
2
votes
1answer
46 views

BloomFilter in ruby should have k hash functions

I am reading the Bloom Filter implementation written in ruby. It should have k hash functions, but it looks like the same hash function is being used with different seed values. Is this a common way ...
0
votes
1answer
33 views

What would be the return type of a cartesian product of a multiset

I am writing a Multiset in Ruby. The Union, Intersection operations where simple and return a MultiSet. But, I am not sure what the return type of the cartesian product should be, should I return an ...
2
votes
1answer
50 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 ...
1
vote
1answer
44 views

Create a collection with “average points” of N items from a pool with items of various points

Let's say I have a question pool to generate exams out of it. Each question contains a difficulty from 1 (hard) to 99 (easy). The questions are available in a hash / array (adapt to your favorite ...
1
vote
1answer
98 views

Should I use expect or should when writing RSpec specs? [closed]

Please can someone explain to me how I should go about deciding whether to use expect or should syntax for my rspec examples. From my understanding we should no longer be using the 'should' syntax. ...
-1
votes
1answer
112 views

Unevenly distributed random number generation [duplicate]

Let's say I have to generate random number from 1 to 100, however, the probability of each number is not 1/100, but a predefined probability. How to generate that number? I use Ruby/Python.
0
votes
1answer
58 views

Calculate which quantity packages to use based on quantity of bookings

In my app, many appointments can be booked for activities. Each activity has many price packages with a price and a quantity. On showing the cart, I need to work out what combination of packages ...
0
votes
1answer
41 views

Ruby on Rails application interfacing with a Datamax barcode printer [closed]

I am trying to find a standalone way to interface with a Datamax M-Class Mark2 label printer through a Ruby on Rails application. I currently have a solution that is working, which i use javascript to ...
0
votes
1answer
128 views

Refactoring a Single Rails Model with large methods & long join queries trying to do everything

I have a working Ruby on Rails Model that I suspect is inefficient, hard to maintain, and full of unnecessary SQL join queries. I want to optimize and refactor this Model (Quiz.rb) to comply with ...
2
votes
0answers
94 views

Splitting up a Rails/Ruby app onto multiple servers

We recently moved a large application to two machines, both running the same codebase. I. Machine A Web server for public facing application Receives web hook call backs from our ESP Handles a ...
0
votes
0answers
98 views

Run RSpec from within a ruby script while refreshing all ruby configs etc

I'm working with a very large project with tons of established tests that include some reasonably complicated environment setups and what not. I've recently run into a situation testing some ...
28
votes
7answers
4k 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 ...
3
votes
3answers
2k views

Ruby IDE code completion [closed]

I just started writing some ruby in my spare time and am currently using Netbeans 7 with the Ruby and Rails plugin v0.111. I'm primarily a Java programmer coming from IntelliJ and Eclipse. One ...
24
votes
2answers
2k views

Do modern languages still use parser generators?

I was researching about the gcc compiler suite on wikipedia here, when this came up: GCC started out using LALR parsers generated with Bison, but gradually switched to hand-written ...
2
votes
2answers
141 views

What kind of exception to ask for out of range arguments?

What type of exception should I throw? I have a console class which describes rectangle of cells which a user can index by passing in a coordinate: width, height = 80, 25 console = ...
0
votes
2answers
1k views

Why doesn't Ruby have implicit conversion of Fixnum into String?

Ruby normally makes things easy. However, it doesn't allow implicitely converting a number to a string: 2.0.0p247 :010 > "a"+1 TypeError: no implicit conversion of Fixnum into String Why is this ...
1
vote
2answers
234 views

Need advice on design in Ruby On Rails

For personal educational purposes I am making a site for a conference. One of the object that exist in a conference is a session, which has different states and in each state it has slightly different ...
4
votes
5answers
2k views

What is a practical way to debug Rails?

I get the impression that in practice, debuggers are rarely used for Rails applications. (Likewise for other Ruby apps, as well as Python.) We can compare this to the usual practice for Java or ...
0
votes
2answers
228 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, ...
26
votes
4answers
3k views

Concrete examples of Python's “only one way to do it” maxim

I am learning Python and am intrigued by the following point in PEP 20 The Zen of Python: There should be one-- and preferably only one --obvious way to do it. Although that way may not be ...
0
votes
1answer
78 views

Android -> Ruby Server Interface -> Mongodb

I've been wrecking my brain about this for a few days. I'll run my scenario by you and hopefully you can help me. In my head this is how it goes: I have an Android App. I want my Android App to make ...
4
votes
3answers
1k views

How can web development bootcamps deliver on their promise? [closed]

I came across the concept of web development bootcamps, these 9-10 week intensive crash courses claim to teach beginners web development and help them get 80k starting salary jobs. Many of you might ...
1
vote
1answer
181 views

Why many Ruby gems won't work on Windows [duplicate]

Most of the gems out there work fine on *nix but not on Windows. First I tried WySQL2, then dosu which shows incompatibility with Ruby 2.0. I tried things on github issues, but no luck. I never had ...
0
votes
0answers
25 views

Is Resque appropriate for an evented application?

As the title says, is Resque appropriate for an evented application that requires a decent amount of speed? I'm working on a server application that emulates the default Minecraft server, and I was ...
3
votes
1answer
94 views

What does it mean that file IO binary flag is only relevant on Windows

I was reading a question and one of the comments mentioned that "The binary flag is only relevant on Windows". Given the context of the question and answer, I interpret this statement as on ...
73
votes
9answers
34k views

Why is Python used for high-performance/scientific computing (but Ruby isn't)?

There's a quote from a PyCon 2011 talk that goes: At least in our shop (Argonne National Laboratory) we have three accepted languages for scientific computing. In this order they are C/C++, ...
6
votes
6answers
803 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 ...
0
votes
2answers
253 views

help me understand Rails and attributes as class methods

This is from the Hartl Rails tutorial. We are automatically logging in a user in the process of creating that user with a callback to #create_remember_token. It works great but there are some things, ...
-3
votes
1answer
186 views

Is there a purely technical term for 'monkey patching' [closed]

EDIT The original title of the question was Is there a non-derogatory term for 'monkey patching'. As I have learned that the term is actually not derogatory, or is at least not meant to be, I changed ...
0
votes
1answer
153 views

JSON - Ruby objects key naming

Ruby object has method/property: def tentakles_count 8 end JavaScript object has key/property: { justEnough: true } Now, when JavaScript gets serialised ruby object via XHR or WebSocket, ...
0
votes
0answers
76 views

Ruby on Rails - branding

I am working on a website, which is to have multiple brands. The core functionality for all brands will be the same, however there will be a number of differences between them. Those differences may ...
2
votes
4answers
291 views

Test Doubles, Mocks and Stubs - when not to use & why, for Ruby, Rspec

I've learned about mocking and stubbing and I've seen how they can help me create great test suites that run blindingly fast and thus speed up my development process hugely. However I've also seen ...
7
votes
3answers
1k 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 ...
4
votes
2answers
5k views

How to execute a Ruby file in Java, capable of calling functions from the Java program and receiving primitive-type results?

I do not fully understand what am I asking (lol!), well, in the sense of if it is even possible, that is. If it isn't, sorry. Suppose I have a Java program. It has a Main and a JavaCalculator class. ...
2
votes
2answers
114 views

How to check robustness in a service that includes multiple points of failure in workflow, including FTP

As part of my workflow, I need to do all these steps in one transaction - I need to ftp files to 2 different FTP servers. - There is also a spreadsheet that gets generated which needs to be FTP'ed. ...
1
vote
4answers
254 views

If I use Ruby Migrations, do I have to use the rest of Ruby on Rails?

I'm currently trying to come up with a database migrations strategy for my organization. This includes getting the database scripts into source control, managing versioning, managing releases to QA / ...
8
votes
3answers
408 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 ...
-2
votes
1answer
4k views

Advantages and disadvantages of PHP/Ruby [closed]

I've been a front-end developer for about two years now, and I'm attempting to break into the server side of things. Ideally I'd like to work for a startup social network on the back-end side so I ...
32
votes
11answers
4k views

Is it okay to make coding style changes on an open source project that doesn't follow best practices?

Recently, I came across a number of open source Ruby (or majority of it was Ruby) projects on GitHub that when checked with a code analyzing tool like Rubocop, create a lot of offenses. Now, most of ...
2
votes
1answer
202 views

Designing and refactoring of payment logic [closed]

Im currently working on an application that helps users to coordinate dinner clubs and all related accounting. (A dinner club is where people in a group, take turns to cook for the rest and then you ...