Tagged Questions
-2
votes
1answer
35 views
Concise way to find max/min with potentially nil value [closed]
I have two arrays, max_of_row (which stores the maximum value in each row) and min_of_col (which stores the minimum value in each col).
I initialize these as max_of_row = [] and min_of_col = [].
...
15
votes
4answers
10k views
Ruby Memory Management
I have been using Ruby for a while now and I find, for bigger projects, it can take up a fair amount of memory. What are some best practices for reducing memory usage in Ruby?
Please, let each ...
2
votes
3answers
103 views
How to integrate rubocop with Rake?
rubocop is a code style checker for Ruby. A similar tool to rubocop, Cane, can be integrated with Rake. I prefer rubocop to Cane since rubocop makes checks based on the Ruby Style Guide and it seems ...
0
votes
3answers
49 views
What is the cleanest way to calculate instance variables in initialize?
Say I have a class that defines a collection of my days and how wacky they are. Is it better to initialize my @scores variable in the initialize function like so:
class WackyDayScorer
attr_reader ...
2
votes
1answer
38 views
Should Conditional Chain Success be Implicit or Explicit
Which is the better practice? To make the logic for your successful case implicit or explicit in a conditional chain?
Please note that the logic is exhaustive in all of the following, so it is really ...
3
votes
3answers
59 views
Testing if an object is a string
I have a function that manipulates a string; however, sometimes my input isn't already a string. For example it could be a path object. I need to convert it to a string because I want to call methods ...
5
votes
3answers
710 views
Automated code sanity check tools for Ruby
What tools do you use for automated code sanity checks and adhering to the coding conventions in your Ruby apps? How do you incorporate them into your process? (I mean tools like roodi, reek, heckle, ...
17
votes
5answers
4k views
Is it good style to explicitly return in Ruby?
Coming from a Python background, where there is always a "right way to do it" (a "Pythonic" way, if you will) when it comes to style, I'm wondering if the same exists for Ruby. I've kind of been using ...
4
votes
4answers
67 views
How to write a complicated condition
Condition constructions are easy to write when you have a simple condition and a possibly complicated body:
if simple_condition_expressed_in_one_liner
complicated_body_that_may_be_long
...
2
votes
1answer
40 views
How do I construct an object in ruby Array Map?
class TestClass
attr_accessor :name, :id
end
values = ["test1", "test2"]
mapped_values = values.map{|value|
test_class = TestClass.new
test_class.name = value
test_class.id = #some random ...
75
votes
10answers
16k views
Ruby coding style guidelines
Is there a document for Ruby that describes some preferred conventions for whitespace, indentation and other style issues?
I found Python's PEP 8 to be very helpful and am looking for something ...
2
votes
4answers
64 views
Ruby: Combine two similar methods into one?
I have two extremely similar methods in my Ruby object for a Rails app. I know they can be combined, I just don't know how. (Extra points if you can find a more beautiful way to handle possible nils ...
1
vote
2answers
63 views
Correct way of writing parentheses in Ruby methods?
What is the "acceptable" or "correct" way to write parentheses in Ruby methods?
Like:
puts doc.instance_of?( self.class.superclass.class )
or:
puts doc.instance_of? ( self.class.superclass.class ...
0
votes
4answers
71 views
Improve readability of large attr_accessor
What should I do when defining constants or attr_accessor symbols that are very large? For example, something like this:
ATTRIBUTES = %w(id name full_name owner private html_url description fork url ...
7
votes
3answers
2k views
Coding style checker or code formatter for Ruby / Rails
When I use C# or Perl, there are some useful tools like StyleCop, FxCop, Perl::Critic and Perltidy. They can check or format my code automatically. Then, are there any equivalent tools for Ruby or ...