Jeff Dean's blog



Jeff DeanJeff Dean
Standup 8/17: RubyMine rebase issues and Ruby truthiness
edit Posted by Jeff Dean on Friday August 21, 2009 at 09:25AM

Interesting Things

Truthiness

You can't make something "falsy" in ruby. For example, let's say you are a good Fowlerite and you are implementing a nil object pattern like so:

class User; end

class NilUser
  def nil?() true end
end

user = NilUser.new

if user
  puts "Access Approved"
else
  puts "Access Denied"
end

If you run that code, even though you've defined .nil? to be true, it will print "Access Approved". Ruby if/unless/else only recognize nil and false to be "falsey".

RubyMine rebase strangeness

When you rebase from the command line and get a merge error, then run the merge tool from RubyMine, the "Your changes" and "Their changes" will be the reverse of what you might think. If you are accustomed to clicking "accept theirs" to mean taking other people's changes, you'll be in for a surprise.

If you botch the git rebase, you can always go back with this awesome git command, brought to you by Peter Jaros:

git reset --hard "master@{ 1 }"