As an experiment, I implemented part of NilCheck using the RuboCop system. I found the node patterns and matcher macros very nice and useful.
More information here: https://github.com/bbatsov/rubocop/blob/f5fed30d4106c8aff7dd27ffef947def530deae1/manual/node_pattern.md