def stringify_table( table, replace_char = '-', pluralize = false ) string = table.to_s.gsub( /([A-Za-z])([A-Z])/, '\1' << replace_char.to_s << '\2' ) string = string.pluralize if pluralize string end
Given a string akin to the name of a table, it returns the related table object; e.g. 'sub_attributes' => SubAttribute.
def tablify_string( string ) eval( string.to_s.gsub( /_id/, '' ).singularize.split( '_' ).collect { |word| word.capitalize }.join ) end