Class: String
Instance Method Summary
collapse
Instance Method Details
47
48
49
|
# File 'lib/aliyun/oss/extensions.rb', line 47
def previous
dup.previous!
end
|
#previous! ⇒ Object
31
32
33
34
|
# File 'lib/aliyun/oss/extensions.rb', line 31
def previous!
self[-1] -= 1
self
end
|
#remove_extended ⇒ Object
95
96
97
|
# File 'lib/aliyun/oss/extensions.rb', line 95
def remove_extended
dup.remove_extended!
end
|
#remove_extended! ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'lib/aliyun/oss/extensions.rb', line 80
def remove_extended!
sanitized_string = ''
each_byte do |byte|
character = byte.chr
sanitized_string << character if character.ascii_only?
end
sanitized_string
end
|
#tap {|_self| ... } ⇒ Object
42
43
44
45
|
# File 'lib/aliyun/oss/extensions.rb', line 42
def tap
yield(self)
self
end
|
51
52
53
|
# File 'lib/aliyun/oss/extensions.rb', line 51
def
downcase.tr('_', '-')
end
|
#underscore ⇒ Object
ActiveSupport adds an underscore method to String so let’s just use that one if we find that the method is already defined
57
58
59
60
61
62
|
# File 'lib/aliyun/oss/extensions.rb', line 57
def underscore
gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").downcase
end
|
#valid_utf8? ⇒ Boolean
65
66
67
|
# File 'lib/aliyun/oss/extensions.rb', line 65
def valid_utf8?
dup.force_encoding('UTF-8').valid_encoding?
end
|