Class: String

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

Overview

This file extends core Ruby classes! Please make sure it doesn’t create conflicts

Instance Method Summary collapse

Instance Method Details

#camel_caseObject

returns camel_case representation of string



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/extension.rb', line 10

def camel_case
  if self.include? '_'
    self.split('_').map{|e| e.capitalize}.join
  else
    unless self =~ (/^[A-Z]/)
      self.capitalize
    else
      self
    end
  end
end

#snake_caseObject

returns snake_case representation of string



5
6
7
# File 'lib/extension.rb', line 5

def snake_case
  gsub(/([a-z])([A-Z0-9])/, '\1_\2' ).downcase
end

#to_wObject

converts string to ‘wide char’ (Windows Unicode) format



23
24
25
# File 'lib/extension.rb', line 23

def to_w
  (self+"\x00").encode('utf-16LE')
end