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
167 168 169 |
# File 'lib/aliyun/oss/extensions.rb', line 167 def __called_from__ caller[1][/`([^']+)'/, 1] end |
#__method__(depth = 0) ⇒ Object
163 164 165 |
# File 'lib/aliyun/oss/extensions.rb', line 163 def __method__(depth = 0) caller[depth][/`([^']+)'/, 1] end |
#expirable_memoize(reload = false, storage = nil) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/aliyun/oss/extensions.rb', line 171 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
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/aliyun/oss/extensions.rb', line 184 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 |