Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/lizarb/ruby/string.rb
Instance Method Summary collapse
- #camelcase ⇒ Object (also: #camelize)
- #ljust_blanks(length) ⇒ Object
- #ljust_zeroes(length) ⇒ Object
- #rjust_blanks(length) ⇒ Object
- #rjust_zeroes(length) ⇒ Object
- #snakecase ⇒ Object (also: #snakefy)
Instance Method Details
#camelcase ⇒ Object Also known as: camelize
6 7 8 |
# File 'lib/lizarb/ruby/string.rb', line 6 def camelcase split("_").map { |s| "#{s[0].to_s.upcase}#{s[1..-1]}" }.join("") end |
#ljust_blanks(length) ⇒ Object
28 29 30 |
# File 'lib/lizarb/ruby/string.rb', line 28 def ljust_blanks length ljust length, " " end |
#ljust_zeroes(length) ⇒ Object
32 33 34 |
# File 'lib/lizarb/ruby/string.rb', line 32 def ljust_zeroes length ljust length, "0" end |
#rjust_blanks(length) ⇒ Object
20 21 22 |
# File 'lib/lizarb/ruby/string.rb', line 20 def rjust_blanks length rjust length, " " end |
#rjust_zeroes(length) ⇒ Object
24 25 26 |
# File 'lib/lizarb/ruby/string.rb', line 24 def rjust_zeroes length rjust length, "0" end |
#snakecase ⇒ Object Also known as: snakefy
12 13 14 15 16 |
# File 'lib/lizarb/ruby/string.rb', line 12 def snakecase gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase end |