Hello, I recently released command_kit, which is a zero-dependency all-in-one kitchen-sink-included kit for building CLI apps. I borrowed some of the functions from dry-inflector since I only needed a very basic inflector for converting file names / command names to Class names. My next goal was to port command_kit to Crystal. However, Crystal does not support Regexp.last_match (which it shouldn’t, because global state), so I refactored the inflector methods to use StringScanner; which improved the performance of underscore but slowed down camelize. Eventually I want to submit a PR back to dry-inflector, however my algorithm deviates slightly from dry-inflector’s original algorithm:
underscore reduces multiple _ and -s to a single _ (ex: Foo---Bar___Baz → foo_bar_baz)
camelize omits any -s (ex: foo-bar → FooBar)
This raised the question about what should the ideal behavior be? Should - be preserved, reduced, or entirely omitted when converting a CamelCase string to under_scored or vice versa?
Personally, I think any underscores or dashes should be stripped when converting from under_scored case to CamelCase. Not sure whether - should be preserved or omitted when converting CamelCase to under_scored case?
Update: I’ve fixed the regression introduced by my StringScanner algorithm where the number of _ or - characters were not being preserved when converting to under_scored. Lost some of the performance gains, but is still ~15% faster than DRY::Inflector#underscore.