Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/mark_facets/ruby/string.rb
Constant Summary collapse
- RANDOM_CHARS =
[('A'..'H').to_a, ('J'..'N').to_a, ('P'..'T').to_a, ('W'..'Z').to_a, ('3'..'9').to_a].flatten
Class Method Summary collapse
Instance Method Summary collapse
- #hexdigest ⇒ Object
- #hexdigest! ⇒ Object
- #md5_hash ⇒ Object
- #to_bool ⇒ Object (also: #to_boolean)
Class Method Details
.cast_from(object) ⇒ Object
36 37 38 |
# File 'lib/mark_facets/ruby/string.rb', line 36 def cast_from(object) object.to_s end |
.random(size = 20) ⇒ Object
30 31 32 33 34 |
# File 'lib/mark_facets/ruby/string.rb', line 30 def random(size = 20) newpass = '' 1.upto(size) { |i| newpass << RANDOM_CHARS[rand(RANDOM_CHARS.size-1)] } return newpass.upcase end |
Instance Method Details
#hexdigest ⇒ Object
8 9 10 |
# File 'lib/mark_facets/ruby/string.rb', line 8 def hexdigest Digest::SHA1.hexdigest(self) end |
#hexdigest! ⇒ Object
12 13 14 |
# File 'lib/mark_facets/ruby/string.rb', line 12 def hexdigest! self.replace(self.hexdigest) end |
#md5_hash ⇒ Object
4 5 6 |
# File 'lib/mark_facets/ruby/string.rb', line 4 def md5_hash Digest::MD5.hexdigest(self).to_s end |
#to_bool ⇒ Object Also known as: to_boolean
16 17 18 19 20 21 22 |
# File 'lib/mark_facets/ruby/string.rb', line 16 def to_bool case self.downcase when 'n', 'no', 'f', 'false', 'nay' return false end return true end |