Files
vagrant-libvirt/spec/support/binding_proc.rb
Darragh Bailey 18ebb9d9ed Enable frozen string across project (#1319)
Turn on frozen string support in all files by using a comment to avoid
enabling across dependencies where it may not work.

Fixes: #1177
2021-06-30 13:27:03 +01:00

27 lines
585 B
Ruby

# frozen_string_literal: true
##
# A simple extension of the Proc class that supports setting a custom binding
# and evaluates everything in the Proc using the new binding.
class ProcWithBinding < Proc
##
# Set the binding for this instance
def apply_binding(bind, *args)
@binding = bind
instance_exec(*args, &self)
end
def method_missing(method, *args)
begin
method_from_binding = eval("method(#{method.inspect})", @binding)
return method_from_binding.call(*args)
rescue NameError
# fall through on purpose
end
super
end
end