Class: String

Inherits:
Object show all
Defined in:
lib/aliyun/oss/extensions.rb

Instance Method Summary collapse

Instance Method Details

#previousObject



75
76
77
# File 'lib/aliyun/oss/extensions.rb', line 75

def previous
  dup.previous!
end

#previous!Object



59
60
61
62
# File 'lib/aliyun/oss/extensions.rb', line 59

def previous!
  self[-1] -= 1
  self
end

#remove_extendedObject



123
124
125
# File 'lib/aliyun/oss/extensions.rb', line 123

def remove_extended
  dup.remove_extended!
end

#remove_extended!Object



108
109
110
111
112
113
114
115
# File 'lib/aliyun/oss/extensions.rb', line 108

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

Yields:

  • (_self)

Yield Parameters:

  • _self (String)

    the object that the method was called on



70
71
72
73
# File 'lib/aliyun/oss/extensions.rb', line 70

def tap
  yield(self)
  self
end

#to_headerObject



79
80
81
# File 'lib/aliyun/oss/extensions.rb', line 79

def to_header
  downcase.tr('_', '-')
end

#underscoreObject

ActiveSupport adds an underscore method to String so let’s just use that one if we find that the method is already defined



85
86
87
88
89
90
# File 'lib/aliyun/oss/extensions.rb', line 85

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

Returns:

  • (Boolean)


93
94
95
# File 'lib/aliyun/oss/extensions.rb', line 93

def valid_utf8?
  dup.force_encoding('UTF-8').valid_encoding?
end