hardscrabble 🍫

By Max Jacobson

Psst. Check out my RubyConf 2017 talk, There are no rules in Ruby.

blog posts

rubí dos

17 Jun 2013

The Ruby Core Team wrote this in October 2011:


  • We continue to provide normal maintenance for 1.8.7 as usual, until June 2012. You can safely assume we provide bugfixes and no incompatibility shall be introduced.

  • After that we stop bugfixes. We still provide security fixes until June 2013, in case you are still using 1.8.7.

  • We will no longer support 1.8.7 in all senses after June 2013.

It’s June 2013.

One of the things that is keeping people using Ruby 1.8.7 must be that it comes with Macs as the default Ruby, and installing newer versions isn’t as easy as it could be. Well this is kind of cool:

Ruby developers will go through the process of installing rvm, rbenv, or chruby to manage multiple Ruby versions so this might not immediately affect the work they do on their personal computers but I think it’s a huge win because it encourages people to casually try Ruby and have a modern experience, be they newbies or experts in other languages. It also makes it easier to require newer versions of Ruby when releasing RubyGems.

I had this in mind while reading What’s new in Ruby 2.0 by Gabriel Fortuna, a speakerdeck I’ll embed here:

Fortuna shows off some of the cool new features Ruby 2.0 offers. Some of them have to do with how the interpreter works more efficiently, which honestly goes over my head right now. But I’m pretty interested in new syntactic features like keyword arguments.

Before Ruby 2.0, if you have a method that has several arguments, you just have to remember their order and which means what or wrap them in a hash. With keyword arguments you can label your arguments for greater clarity. This blog post has a great overview.

Another change is “Refinements” which aims to be a more elegant way to modify class behaviors in lieue of monkey patching. You can still crack open and modify classes in crazy ways, but this lets you localize those changes to contexts, for the sake of being a little safe about it.

I’d love to use these features, the others Fortuna covers, and what I’m sure are plenty of more little cool changes. Fortuna mentions that the next major version of Ruby on Rails, Rails 4, is designed for Ruby 2.0. That’s exciting. I wonder how fast the community will adopt these as the new de facto standard.

random emoji in prompt

13 Jun 2013

Edit: This post is kind of sloppy. Please consider reading this later, similar post instead.

So this is fun. Most of us at school have some symbol or emoji in our bash prompts. I’ve had a little piggie emoji for a few weeks which has served me fine but I’d like to introduce some… chance into my life. I want to have a random emoji in my prompt. Originally I wanted a new icon on a per-terminal-session basis but then I decided I wanted a new one after every command.

Here’s a simple Ruby script to print a random emoji from a nice subset of positive ones (no murder weapons or pills or bills)1:

# encoding: UTF-8
emoji = %w{🐖 🐊 🐗 💾 💡 ☕ 🍆 🍆 🍆 🍆 🎈 👾}
print emoji[rand(emoji.length)]

I have this exact file saved in my home directory. It’s a dotfile (hidden file) because for the most part I don’t want to see it. Maybe there’s a better place to put it.

In order to get the output of that script into my prompt, I need to udpate my PS1 bash variable. In order to refresh it after every command I need to do this weird thing I’ve never done before (this goes in my bash profile):

function set_prompt {
  export PS1="[\@] [\W]\n$(~/.emoji.rb)  "
export PROMPT_COMMAND=set_prompt

The PROMPT_COMMAND variable can be assigned some shell script code to run before every drawing of the prompt. In this case, it’s calling a function called set_prompt, which runs the Ruby program and interpolates its response into the PS1 variable, so it’s different each time.

In order for the Ruby script to be executable by other code, we need to adjust its permissions. If you don’t do this, you get an error instead of a pig. You can run chmod a+x ~/.emoji.rb.

I’m happy. I’m gonna keep adding / removing / futzing with my emoji set. The code should work with any number of items in there, so I may go wild. The easiest way to get at them on a Mac is, from any text field, the Edit menu, then Special Characters (tip via classmate Samantha Radocchia’s blog).

If you try this and get it working, let me know on twitter at @maxjacobson #sleaze

EDIT on July 4

Actually this code totally sucks. It’s not at all necessary to use PROMPT_COMMAND. You can change this:

function set_prompt {
  export PS1="[\@] [\W]\n$(~/.emoji.rb) "
export PROMPT_COMMAND=set_prompt


export PS1="[\@] [\W]\n\$(~/.emoji.rb) "

The only breakthrough I had is that \$(function_name) runs the function over and over where $(function_name) only runs it once. No idea why.

This fixes the bug where the Terminal wasn’t remembering my current working directory and auto-cd-ing into it when I open a new tab.

It should also be easier to drop this into your current prompt. Just add \$(~/.emoji.rb) wherever in your PS1 you want it.

  1. Note: I’m painfully aware that most of those emoji are probably not showing up for you in your browser right now. I don’t understand what exactly emoji are or how they work enough to try to fix that. If you want to do this you will probably need to re-populate that line with your favorite picks.