Method: String#class_name_to_filename

Defined in:
lib/openc3/core_ext/string.rb

#class_name_to_filename(include_extension = true) ⇒ String

Converts a String representing a class (i.e. “MyGreatClass”) to a Ruby filename which implements the class (i.e. “my_great_class.rb”).

Parameters:

  • include_extension (Boolean) (defaults to: true)

    Whether to add '.rb' extension

Returns:

  • (String)

    Filename which implements the class name



290
291
292
293
294
295
296
297
298
299
300
# File 'lib/openc3/core_ext/string.rb', line 290

def class_name_to_filename(include_extension = true)
  string = self.split("::")[-1] # Remove any namespacing
  filename = ''
  length = string.length
  length.times do |index|
    filename << '_' if index != 0 and string[index..index] == string[index..index].upcase
    filename << string[index..index].downcase
  end
  filename << '.rb' if include_extension
  filename
end