Module: Kernel
- Defined in:
- lib/aliyun/oss/extensions.rb
Instance Method Summary collapse
- #__called_from__ ⇒ Object
- #__method__(depth = 0) ⇒ Object
- #expirable_memoize(reload = false, storage = nil) ⇒ Object
- #require_library_or_gem(library, gem_name = nil) ⇒ Object
Instance Method Details
#__called_from__ ⇒ Object
139 140 141 |
# File 'lib/aliyun/oss/extensions.rb', line 139 def __called_from__ caller[1][/`([^']+)'/, 1] end |
#__method__(depth = 0) ⇒ Object
135 136 137 |
# File 'lib/aliyun/oss/extensions.rb', line 135 def __method__(depth = 0) caller[depth][/`([^']+)'/, 1] end |
#expirable_memoize(reload = false, storage = nil) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/aliyun/oss/extensions.rb', line 143 def expirable_memoize(reload = false, storage = nil) current_method = RUBY_VERSION > '1.8.7' ? __called_from__ : __method__(1) storage = "@#{storage || current_method}" if reload instance_variable_set(storage, nil) else if cache = instance_variable_get(storage) return cache end end instance_variable_set(storage, yield) end |
#require_library_or_gem(library, gem_name = nil) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/aliyun/oss/extensions.rb', line 156 def require_library_or_gem(library, gem_name = nil) if RUBY_VERSION >= '1.9' gem(gem_name || library, '>=0') end require library rescue LoadError => library_not_installed begin require 'rubygems' require library rescue LoadError raise library_not_installed end end |