From 2e00481ab7dfa35deaa980c3100a974349dc345f Mon Sep 17 00:00:00 2001 From: strcmp <28xdb6+fvutuvy4f@grr.la> Date: Mon, 28 Dec 2015 11:26:11 +0000 Subject: make 'Pry::Config::Default' less of a special case by adding Pry::Config::Lazy --- lib/pry/config/lazy.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/pry/config/lazy.rb (limited to 'lib/pry/config/lazy.rb') diff --git a/lib/pry/config/lazy.rb b/lib/pry/config/lazy.rb new file mode 100644 index 00000000..c32f8076 --- /dev/null +++ b/lib/pry/config/lazy.rb @@ -0,0 +1,26 @@ +module Pry::Config::Lazy + LAZY_KEYS = {} + LAZY_KEYS.default_proc = lambda {|h,k| h[k] = [] } + + module ExtendModule + def lazy_implement(method_name_to_func) + method_name_to_func.each do |method_name, func| + define_method(method_name) do + if method_name_to_func[method_name].equal?(func) + method_name_to_func[method_name] = instance_eval(&func) + LAZY_KEYS[self.class] |= method_name_to_func.keys + end + method_name_to_func[method_name] + end + end + end + end + + def self.included(includer) + includer.extend(ExtendModule) + end + + def lazy_keys + LAZY_KEYS[self.class] + end +end -- cgit v1.2.1