Module: Logrithm::Utils::Syringe
- Defined in:
- lib/logrithm/utils/syringe.rb
Class Method Summary collapse
Class Method Details
.inject(*km) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/logrithm/utils/syringe.rb', line 6 def inject(*km) return unless km.size == 2 && km.first.is_a?(Class) && km.last.is_a?(String) klazz, method = km name = scramble "Logrithm@#{klazz}##{method}" return if klazz.ancestors.map(&:name).include? "Kernel::#{name}" Kernel.const_set( name, Module.new do define_method method do |*args| $♯ = self super(*args) end end ) klazz.prepend Kernel.const_get name end |
.scramble(str) ⇒ Object
25 26 27 |
# File 'lib/logrithm/utils/syringe.rb', line 25 def scramble(str) str.gsub(/[:#@?!]/, ':' => ':', '#' => '#', '@' => '@', '?' => '?', '!' => '!', '=' => '=') end |