1. Keep Ruby Weird 2016

    Keep Ruby Weird could easily be called “Remember Ruby’s Fun”. It’s a one day, one track conference in Austin that pays homage to the days of why’s (poignant) Guide to Ruby. Born in Austin, whose slogan is “Keep Austin Weird”, the city and conference didn’t disappoint. After parking my car in the hotel garage, I stepped into the elevator, and met with this disaster:

    Two columns of elevator buttons reading from left to right and top to bottom -1, ⋆1, -3, -2, 0, -1.

    On my way home the elevator stopped in the lobby with 3 men in it. I waited for someone to exit but they stood fast looking confused. I pressed “-2” to go to my floor in the garage. When the doors opened one tried to step off but the others stopped him. He exclaimed, “Where are we supposed to get off?” I can’t confirm it but in my heart I believe they’re still on that elevator.

    Read More
  2. Know Ruby: private_constant

    Constants are a part of your public interface. They can be an efficient way to share static values. But what if you don’t want to share? Some constants, like some methods, are intended for internal use only.

    To find the constants associated with a class or module you can call constants on it. The Float class provides a lot of useful information via constants.

    Read More
  3. RubyKaigi 2016

    Last week I attended RubyKaigi, the most prestigious Ruby conference in the world. Held in Japan 10 times since 2006, it boasts an opening keynote by Matz and attendance by nearly every core committer.

    Kyoto International Convention Center

    Hosted in Kyoto for the first time ever, it was also my first time attending. The organizers were able to book the Kyoto International Conference Center. It’s a stunning venue that hosted the 1992 United Nations convention where the Kyoto Protocol was drafted. Originally built in the 60’s, after 50 years it still manages to look futuristic without appearing out of place amid the beautiful landscape.

    Read More
  4. 5 Tips for Writing a Legible Regexp

    Regular expressions can be tricky to write and downright impossible to read. They can also be incredibly useful. Striking a balance between power and legibility is achievable. Here are five of the best ways I know to do it.

    Read More
  5. Clear Intentions: Do you speak 3?

    It’s easy to mistake current knowledge for universal knowledge. Decisions that were straightforward a year ago are a mystery today. We’ve all done it. Why did I pick that value? What made them do it that way?

    We check the commit history, question co-workers, and spend time learning or re-learning the domain. Hopefully the problem isn’t time critical.

    One way to mitigate this is to make your code clarify your intent.

    Read More
  6. Proper Regexp Anchoring

    In regular expressions, ^ does not match the start of a string. It might in other languages but not Ruby. That’s part of what makes this mistake so common. While we’re on the topic, $ doesn’t match the end of a string.

    Read More
  7. Know Ruby: with_index

    Have you ever used with_index? Not each_with_index which is similar but slightly different. Did you know that you can do map.with_index?

    If you’ve written code like this:

    i = 0
    lines.map do |line|
      i += 1
      "#{i}) #{line}"
    end
    

    or

    lines.each_with_index do |line, i|
      puts "#{i + 1}) #{line}"
    end
    

    then keep reading.

    Read More
  8. Don't Forget About Infinite Enumerators

    When was the last time you created an Enumerator? We use enumerables all over the place but it’s rare to see Enumerator.new. If I’m being honest, sometimes I forget it’s an option. I’m guessing you might as well.

    Enumerators don’t have to be infinite but I find that’s where the power lies. With finite enumerations your immediately limiting where they can be used. They come with an extra expectation that must be addressed. Are there enough elements for me? When they’re infinite you can just go crazy.

    Read More
  9. Improving Large Rails Apps with Service Objects

    Nothing has improved my Rails apps more than service objects. A couple of weeks ago, I was asked to help out with an established Rails app. I found a User model that included 28 modules. All but 8 were namespaced under Users. A core object in your system, used everywhere, and it’s thousands of lines long. How many features have been bolted onto this model? When you look at a method, which feature does it belong to?

    Madness like this can be sidestepped with service objects.

    Let’s start at a time before 28 includes. Let’s start at the beginning. Imagine you’ve started a SaaS business. It’s a help desk. Soon you have clients signing up. Then their users are creating accounts and receiving support.

    Want to make your clients happy? Make their users happy. You’ve decided to add a welcome email for those users. It’ll provide a friendly hello and tips on how to use the help desk.

    Where does your new code go?

    Read More
  10. Don't tie jQuery to the Rails

    rail road tracks Photo by Kevin Moreira licensed under CC. The photo has been modified.

    It’s time for jQuery to go. It’s a great library but it’s not a part of Rails.

    I was recently auditing a site for dependencies. Skimming the list of JavaScript libraries I blew right by jQuery. Then a thought popped into my head. The bits of dynamic front-end were built using React. Where was jQuery being used?

    Read More