Questions about Ruby, dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features.
1
vote
0answers
37 views
Can someone explain how this ruby basic-calculator code handles addition and subtraction? [migrated]
So I was working on a Codewars problem here, and found some code posted to Github that works out-of-the-box. Problem is, I don't understand how part of it works. Here are the Codewars directions:
...
-5
votes
1answer
40 views
Recoding Ruby to PHP [closed]
I have been tasked with recoding a file that is currently written in Ruby, over to PHP. My knowledge of PHP is intermediate, but my knowledge of Ruby is very basic. Almost all of the files except ...
-2
votes
1answer
55 views
Can Ruby or Python be a viable option to support advanced statistical analysis? [closed]
I'm normally creating software for simple applications of recording data from forms and displaying those in a customized fashion, using Ruby/Rails. I'm now trying to assist a statistical analyst in ...
0
votes
1answer
45 views
better idiom for selecting id of single record matched using alternative primary key?
Say I have a model Foo with normal integer primary key (id) and an "alternate" primary key "bar" that's a string.
To complicate matters, Foo supports soft deletes, so it has a boolean property ...
0
votes
0answers
30 views
Is listing Types in documentation a code smell
I'm documenting a ruby application and looking closely at YARD. I like the increased structure provided over RDoc, but I'm unsure about the Type declaration. In YARD, you can do something like
...
0
votes
2answers
87 views
Refactoring case-when statement [duplicate]
The Product model which can have 2 price tables. The method price calculates the price of the product based on product's price table which is defined by price_table field.
class Product < ...
2
votes
3answers
138 views
Which is the convention in Rails to perform calculations and display the results?
So I'm working on a personal project on Rails to learn more about this framework, and I wanted to add a feature in which the user choose a particular record from the view, and after some calculations ...
1
vote
0answers
202 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
3answers
61 views
Replace repeated timestamp with variable in tests
I have couple hundred tests and I work with date/time a lot. In some tests, I aim for output format, elsewhere, I check date ranges. Therefore, my tests have lots of these:
FactoryGirl.create(:foo, ...
1
vote
0answers
71 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
2answers
80 views
Ruby Terminology Question: Implicit Declaration or no declaration at all?
I have a question, because in most serious sources I read, all say the same No variable is ever declared in Ruby, but still I have doubts, because according to what I was taught in my university ...
2
votes
0answers
71 views
Writing a gem supporting compiled languages with Rake. How to test?
I want to create a gem that extends the functionality of Rake, creating commands for compiling .NET code.*
Basically, I want to be able to write a Rakefile like this:
desc "Build main executable"
...
-1
votes
1answer
85 views
Is obsolete to study older versions of Ruby and RoR? [closed]
I want to study Ruby and RoR for some things I'll have to make, but almost every book, videos or any kind of source I find is outated, where the most current book I could find (link here) is one of ...
1
vote
0answers
83 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 ...
0
votes
1answer
141 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
2answers
298 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, ...
2
votes
1answer
66 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
44 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
2answers
73 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
48 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
60 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 ...
1
vote
1answer
180 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
194 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
67 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
71 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 ...
3
votes
0answers
155 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 ...
1
vote
0answers
178 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 ...
8
votes
2answers
353 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 ...
29
votes
2answers
3k 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 ...
0
votes
1answer
191 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
2answers
355 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 = ...
1
vote
2answers
376 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
115 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 ...
1
vote
2answers
2k 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 ...
3
votes
1answer
119 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 ...
0
votes
2answers
236 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, ...
-3
votes
1answer
214 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
212 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, ...
1
vote
2answers
247 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 ...
2
votes
2answers
119 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. ...
2
votes
4answers
401 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 ...
-2
votes
1answer
6k 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 ...
2
votes
2answers
102 views
Auxiliary space complexity of map vs map!
I'm curious about the difference in space complexity between map and map! in ruby.
If I have the methods:
def mult_by_two(arr)
arr.map {|i| i * 2 }
end
def mult_by_two!(arr)
arr.map! {|i| i * 2 ...
32
votes
11answers
5k 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
68 views
scoping concern when dealing with coupling
I'm learning ruby (and OOP in the process) and I find keep having to write the same patterns when logging progress so I want to wrap this up in a logging library that my other code can then just pass ...
0
votes
6answers
439 views
How do I explain a ruby method with a real-world analogy? [closed]
I am looking for a good analogy to help the concept of a method in ruby stick in my head. When I truly understand a concept, an image flashes in my mind that relates something physical to the abstract ...
0
votes
0answers
650 views
Ruby module namespacing advice
in my current project have:
module Stats
class Site
...
end
class Product
def initialize(product_id)
@product_id = product_id
end
end
class Profile
...
end
end
...
0
votes
1answer
209 views
Dealing with 'dirty' Ruby on Rails client [closed]
I had to leave a startup about a month ago because of lack of funding. Basically, this client wanted an application to allow contractors to create, update, read, and delete yardsigns. Straight forward ...
1
vote
2answers
179 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 ...
0
votes
1answer
628 views
ruby for desktop app or web app development [closed]
i am a beginner to ruby . i just did some
minor research about why RUBY ? why choose RUBY ? whats new in it.
Whenever i do type in a word RUBY in google search there comes a
suggestion like RUBY on ...