Why not take this a step further:

```
require 'yaml'
yaml = YAML.load(result)
if no_env:
    yaml.delete('environment')
puts yaml.to_yaml
```