Moving files in Rails using String
Since ruby allow for really easy overriding of objects and classes, I decided to make it easier and cleaner to move my files. Here is how you currently do it:
I know this isn’t a huge deal, but I would like to clean it up a little bit. I used an initializer (RAILS_ROOT/config/initializers/core_extensions.rb) to override the String class as such:
class String def move(to = nil) if to && File.exist?(self) FileUtils.move(self, to) end end end
This allows me to do the following to move files:
I though it was pretty cool!
1 thought on “Moving files in Rails using String”
nice job – thanks a lot for this cool idea!
it’s one of these “nice to have” things ^^