Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/lafcadio/util.rb

Instance Method Summary collapse

Instance Method Details

#camel_case_to_underscoreObject

Returns the underscored version of a camel-case string.



59
60
61
# File 'lib/lafcadio/util.rb', line 59

def camel_case_to_underscore
	( gsub( /(.)([A-Z])/ ) { $1 + '_' + $2.downcase } ).downcase
end

#pad(size, fillChar) ⇒ Object

Left-pads a string with fillChar up to size size.

"a".pad( 10, "+") -> "+++++++++a"


68
69
70
71
72
73
74
# File 'lib/lafcadio/util.rb', line 68

def pad(size, fillChar)
	string = clone
	while string.length < size
		string = fillChar + string
	end
	string
end

#underscore_to_camel_caseObject

Returns the camel-case equivalent of an underscore-style string.



79
80
81
# File 'lib/lafcadio/util.rb', line 79

def underscore_to_camel_case
	capitalize.gsub( /_([a-zA-Z0-9]+)/ ) { |s| s[1,s.size - 1].capitalize }
end