<p>I'd like to write a Ruby snippet that gets run when my Gem is first installed via <code>[sudo ]gem install mygem</code>.  Can it be done?</p>

You can try to do this using call of OS commands. I'll quote eample from irb but you can do same in your scripts too.
```
```
irb(main):001:0> system 'gem list | grep rails'
rails (2.1.1, 2.1.0)
=> true
irb(main):002:0> system 'gem list | grep railssssss'
=> false
```
```
You can use result of this command as the condition of your snippet execution.