Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core/string.rb

Instance Method Summary collapse

Instance Method Details

#to_classnameObject

Returns a new string which supposed to represent a class name in accordance

with Ruby class naming convention

"my_class_name".to_classname
# => "MyClassName"


9
10
11
# File 'lib/core/string.rb', line 9

def to_classname
  split(/[ _-]/).map(&:capitalize).join
end

#to_filename(prefix = nil) ⇒ Object

Returns a new string which supposed to represent a file name in accordance with folder/file naming convention.

"my new script".to_filename
# => "my_new_script.rb"

# using with prefix
"my new script".to_filename :test
# => "my_new_script_test.rb"


24
25
26
27
# File 'lib/core/string.rb', line 24

def to_filename(prefix = nil)
  split(/[ _-]/).map(&:downcase).join('_') + 
    (prefix ? "_#{prefix}" : "") + ".rb"
end