Method: CrossCase.transform

Defined in:
lib/mega/crosscase.rb

.transform(mid) ⇒ Object

Return an alternate name for the given method id mid. If the method id is an under_barred method, returns a camelCased version, and vice-versa. If no alternate is called for, returns nil.



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/mega/crosscase.rb', line 210

def self::transform( mid )
  methodName = mid.to_s
  transformedName = ''

  # camelCased methods
  if /[A-Z]/.match( methodName ) && !/_/.match( methodName )
    transformedName = methodName.gsub( /([a-z0-9])([A-Z])/ ) {|match|
        $1 + '_' + $2
    }.downcase
      
  # underbarred_methods
  elsif !/A-Z/.match( methodName ) && /[a-z0-9]_[a-z]/.match( methodName )
    transformedName = methodName.gsub( /([a-z0-9])_([a-z])/ ) {|match|
        $1 + $2.upcase
    }

  else
    transformedName = nil
  end
  
  return transformedName
end