Module: Janeway::AST::Helpers
- Defined in:
- lib/janeway/ast/helpers.rb
Overview
Helper methods for AST Expressions.
Class Method Summary collapse
-
.camelcase_to_underscore(str) ⇒ String
Lowercase, with underscores.
Class Method Details
.camelcase_to_underscore(str) ⇒ String
Returns lowercase, with underscores.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/janeway/ast/helpers.rb', line 9 def self.camelcase_to_underscore(str) found_uppercase = false chars = [] str.each_char do |char| if char.ord.between?(65, 90) # ascii 'A'..'Z' inclusive chars << '_' chars << (char.ord + 32).chr found_uppercase = true else chars << char end end return str unless found_uppercase chars.shift if chars.first == '_' chars.join end |