Posts by Jason Noble:
Rubocop is a Ruby static code analyzer. Rubocop utilizes a number of style rules, which it calls “Cops”, hence the name.
I picked a cop at random, and wanted to see what it looks for in my Ruby code. So let’s take a look at Parameter Lists
echo ‘2.1.5’ > .ruby-version
echo ‘davinci_coders’ > .ruby-gemset
Here I’m going into my practice directory and making a new one. I then setup the directory to have RVM load Ruby 2.1.5 and the davinci_coders gemset. Next I need to add the guard-rubocop gem.
Next we need to bundle in order to install these gems. Then we’ll initialize guard.
Now we need to tell Guard to ignore the Guardfile.
We’ll fire up Guard, and we get no offenses. Let’s add a Ruby file called program_1.rb.
# I’m looking at https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/metrics/parameter_lists.rb
def foo2(param1, param2)
puts param1, param2
def foo3(param1, param2, param3)
puts param1, param2, param3
def foo4(param1, param2, param3, param4)
puts param1, param2, param3, param4
def foo5(param1, param2, param3, param4, param5)
puts param1, param2, param3, param4, param5
def foo6(param1, param2, param3, param4, param5, param6)
puts param1, param2, param3, param4, param5, param6
def foo7(param1, param2, param3, param4, param5, param6, param7)
puts param1, param2, param3, param4, param5, param6, param7
def foo8(param1, param2, param3, param4, param5, param6, param7, param8)
puts param1, param2, param3, param4, param5, param6, param7, param8
Now our guard gives us three offenses:
So it looks like Rubocop will complain if your method has more than 5 parameters. Looks like this preference comes from the Ruby Style Guide.
I’ll have to remember to have 4 or less parameters for any methods I create in the future.
Although, I could configure Rubocop to allow me up to 7 parameters:
No, that’s probably a bad idea. Nevermind.
Ok, I’m tired of looking this up, so I’m going to document it here for future me. We have a branching strategy: maint-2014.04.04 maint-2014.04.18 … master When I create a new branch based off master, I name it 1234567890_some_short_summary_master. Later I determine it should have been based off maint-2014.04.04. Here’s the process: [code] git checkout […]
A co-worker asked if RubyMine has the ability to increase/decrease the font size (say if you were presenting on a projector). I didn’t know, but I researched it and here’s how you enable font size changes. First open RubyMine. Go to RubyMine -> Preferences. Select Keymap from the list on the left In the upper […]
Recently, one of my students Raj Solanki blogged about some podcasts that he recently found. For the past month or so, I’ve been listening to several podcasts. I listen on my iPod, but I’ve found the built in Podcasts app frankly sucks. A co-worker introduced me to Downcast, which is an alternative which ROCKS. My […]
tl;dr: Solution I’m an Ruby on Rails instructor for the DaVinci Coders program in Louisville, CO. I teach a class called Building the Toolbelt of a Junior Ruby on Rails Developer, where we teach students how to use Ruby on Rails, as well as the other tools software engineers use in their daily work. Recently, […]
One of my previous students, Ross Kinney recently blogged about an error he encountered: [code] Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://s3.amazonaws.com/production.s3.rubygems.org/gems/multi_json-1.7.7.gem) [/code] It turns out that some of the OS X SSL Certs were out of date and he fixed it by running: [code] rvm osx-ssl-certs update all […]
I recently imported a bunch of stories into Pivotal Tracker via the Import CSV function. This worked like a charm, the problem was I wanted all the stories to be requested by a different user than what was in the CSV file. I could use the web browser to do this, but that would take […]
I recently updated my Homebrew install and installed the latest mysql (brew update && brew upgrade mysql) to 5.6.12. However, when I tried to upgrade my mysql2 gem from 0.3.11 to 0.3.12, I was getting the following error: [shell] *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary […]
Ran into an interesting issue at work today. My pair (Dave) and I opened a pull request yesterday and I checked the status this morning. It showed that Dave had closed it this morning. I asked him if he had intended to merge it, and he said he hadn’t closed it. The weird thing was […]
I have a script I want to run in rails console, but I don’t want to log the SQL and such. So I googled how to turn off all logging in Rails 3 console. Unfortunately, all the answers were old, so here’s how I did it: [ruby] Logging.logger.root.level = ‘off’ [/ruby]