Class: Autodoc::Name
- Inherits:
-
Object
- Object
- Autodoc::Name
- Defined in:
- lib/ratatui_ruby/devtools/tasks/autodoc/name.rb
Overview
Wraps a name string with case conversion utilities.
Ruby uses snake_case. Constants use PascalCase. Converting between them by hand invites typos. This class handles the conversion.
- string
-
The name string.
Instance Method Summary collapse
-
#snake ⇒ Object
Converts the name to snake_case.
-
#to_s ⇒ Object
Returns the original string.
Instance Method Details
#snake ⇒ Object
Converts the name to snake_case.
Example
Autodoc::Name.new("BarChart").snake # => "bar_chart"
21 22 23 24 25 26 |
# File 'lib/ratatui_ruby/devtools/tasks/autodoc/name.rb', line 21 def snake string.to_s .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase end |
#to_s ⇒ Object
Returns the original string.
29 30 31 |
# File 'lib/ratatui_ruby/devtools/tasks/autodoc/name.rb', line 29 def to_s string.to_s end |