What I would like in Ruby 3

John Bachir's Code Blog
January 01, 2014

Ruby development is hurtling along these days. In 2012 1.9 finally became the norm, and in 2013 we got both 2.0 and 2.1. All of these versions brought small but steady feature improvements.

Here are some thoughts on how I would like the language to change, possibly appropriate for Ruby 3 or Ruby 4.

Methods consistently as . . .

Read More

Sandi Metz's Rules

John Bachir's Code Blog
November 24, 2013

In episode 87 of the fantastic Ruby Rogues podcast, Sandi Metz shares these programming rules:

  • Your class can be no longer than 100 lines of code.
  • Your methods can be no longer than four, maybe five lines of code.
  • You can pass no more than four parameters and you can’t just make it one big hash.
  • Your Rails . . .

Read More

The classic behavior mocking dilemma

John Bachir's Code Blog
November 24, 2013

We would like our tests to not inappropriately cross over layers of the system (such as accessing the database), and we would like our tests to not be dependent on implementation. Unfortunately, these two concerns are often at odds with one another.

Let's say you are testing this method:

class Foo
 def bar
 Bar.find( . . .

Read More

Putting your rbenv-managed bundler-specified executables in your PATH (more) securely

John Bachir's Code Blog
November 24, 2013

There have been a smattering of solutions offered over the years for getting rid of bundle exec. To me they all have drawbacks -- they either solve the problem at the wrong layer, involve remembering an extra step, require a manually-managed whitelist, or are messy for some other reason.

Read More

Why it's a good idea to put a newline at the end of every file

John Bachir's Code Blog
November 24, 2013

I will today settle one of the great issues of our time: whether or not to always put a newline at the end of a file.There are two reasons why it's a good idea, and zero reasons why it's a bad idea.

Let's consider these files:

https://gist.github.com/4010011

The first reason: when using various command . . .

Read More

sane_timeout: a replacement for Ruby's standard library Timeout

John Bachir's Code Blog
November 24, 2013

Ruby's Timeout library had a serious problems before 1.9: it would sometimes not timeout. This was solved by system-timer(see the readme for more background). But in 1.9, we finally have a Timeout thatreliablytimes out, joy. However, it still has some problems.

As some quick background, here is the basic usage:

require . . .

Read More

The somewhat peculiar behavior of Ruby's Thread#raise

John Bachir's Code Blog
November 24, 2013

Here's something that's perhaps not entirely obvious: when you call Thread#raise, the exception will be raised at whatever point of execution that thread happens to be at.

require 'thread'

t = Thread.new{
 sleep 0.1
 sleep 0.1
 sleep 0.1
 sleep 0.1
 sleep 0.1
}

sleep rand(4) * 0.1 . . .

Read More

Archive
   Subscribe by email and never miss a post.