Module: Upyun::Purge::BaseExtend
- Included in:
- Upyun::Purge
- Defined in:
- lib/upyun/purge/base_extend.rb
Instance Method Summary collapse
- #define_attribute(attr_name) ⇒ Object
- #random_number(len = 20) ⇒ Object
- #random_string(len = 20) ⇒ Object
Instance Method Details
#define_attribute(attr_name) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/upyun/purge/base_extend.rb', line 4 def define_attribute( attr_name ) # define read mehtod for class and instance class_eval(" @@#{attr_name} = nil unless defined? @@#{attr_name} def self.#{attr_name} @@#{attr_name} end ", __FILE__, __LINE__ + 1) class_eval(" def #{attr_name} @@#{attr_name} end ", __FILE__, __LINE__ + 1) # define write mehtod for class and instance class_eval(" @@#{attr_name} = nil unless defined? @@#{attr_name} def self.#{attr_name}=(obj) @@#{attr_name} = obj end ", __FILE__, __LINE__ + 1) class_eval(" def #{attr_name}=(obj) @@#{attr_name} = obj end ", __FILE__, __LINE__ + 1) end |
#random_number(len = 20) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/upyun/purge/base_extend.rb', line 43 def random_number( len = 20 ) chars = ("0".."9").to_a newpass = "" 1.upto(len) { |i| newpass << chars[Kernel.rand(chars.size-1)] } newpass end |
#random_string(len = 20) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/upyun/purge/base_extend.rb', line 36 def random_string( len = 20 ) chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a newpass = "" 1.upto(len) { |i| newpass << chars[Kernel.rand(chars.size-1)] } newpass end |