Class: String

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

Instance Method Summary collapse

Instance Method Details

#downcase_firstObject

首字母变小写



11
12
13
14
# File 'lib/mybatis/util/string_ext.rb', line 11

def downcase_first
  str = "#{self}"
  "#{str[0].downcase}#{str[1,str.size]}"
end

#replace_underline_upcase_toObject

去掉下划线并把后一个字母转换成大写 mybatis_cli => MybatisCli



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mybatis/util/string_ext.rb', line 30

def replace_underline_upcase_to
  str = ''
  next_to_downcase = false
  self.each_char do |ch|
    if next_to_downcase
      str << ch.upcase
      next_to_downcase = false
      next;
    end
    str << ch unless next_to_downcase = (ch == '_')
  end
  str
end

#replace_upcase_to_underlineObject

把大写字母转换成小写字母并在前面加下划线 MybatisCli => mybatis_cli



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mybatis/util/string_ext.rb', line 17

def replace_upcase_to_underline
  str = ''
  self.each_char do |ch|
    if /[A-Z]/ =~ ch
      str << "_#{ch.downcase}"
    else
      str << ch
    end
  end
  str
end

#upcase_firstObject

首字母变大写



5
6
7
8
# File 'lib/mybatis/util/string_ext.rb', line 5

def upcase_first
  str = "#{self}"
  "#{str[0].upcase}#{str[1,str.size]}"
end