Sha256: 712706d4cd5205fbd3021016d2a71080e5a37f552752d236ab31c4ffac609f97
Contents?: true
Size: 489 Bytes
Versions: 58
Compression:
Stored size: 489 Bytes
Contents
# frozen_string_literal: true module EacRubyUtils class Inflector class << self VARIABLE_NAME_PATTERN = /[_a-z][_a-z0-9]*/i.freeze def variableize(string) r = string.gsub(/[^_a-z0-9]/i, '_').gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase m = VARIABLE_NAME_PATTERN.match(r) return r if m raise ::ArgumentError, "Invalid variable name \"#{r}\" was generated " \ "from string \"#{string}\"" end end end end
Version data entries
58 entries across 58 versions & 3 rubygems