Module: FakeFS::Kernel
- Defined in:
- lib/fakefs/kernel.rb
Overview
Kernel Module
Class Attribute Summary collapse
-
.captives ⇒ Object
Returns the value of attribute captives.
Class Method Summary collapse
-
.hijack(name, &block) ⇒ Object
NOTE: maybe private.
- .hijack! ⇒ Object
- .unhijack! ⇒ Object
Class Attribute Details
.captives ⇒ Object
Returns the value of attribute captives.
7 8 9 |
# File 'lib/fakefs/kernel.rb', line 7 def captives @captives end |
Class Method Details
.hijack(name, &block) ⇒ Object
NOTE: maybe private
29 30 31 32 |
# File 'lib/fakefs/kernel.rb', line 29 def self.hijack(name, &block) captives[:original][name] = ::Kernel.method(name.to_sym) captives[:hijacked][name] = block || proc { |_args| } end |
.hijack! ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/fakefs/kernel.rb', line 10 def self.hijack! captives[:hijacked].each do |name, prc| ::Kernel.send(:remove_method, name.to_sym) ::Kernel.send(:define_method, name.to_sym, &prc) ::Kernel.send(:private, name.to_sym) end end |
.unhijack! ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/fakefs/kernel.rb', line 18 def self.unhijack! captives[:original].each do |name, _prc| ::Kernel.send(:remove_method, name.to_sym) ::Kernel.send(:define_method, name.to_sym, proc do |*args, **kwargs, &block| ::FakeFS::Kernel.captives[:original][name].call(*args, **kwargs, &block) end) ::Kernel.send(:private, name.to_sym) end end |