summaryrefslogtreecommitdiff
path: root/lib/pry/config/lazy.rb
diff options
context:
space:
mode:
authorstrcmp <28xdb6+fvutuvy4f@grr.la>2015-12-28 11:26:11 +0000
committerstrcmp <28xdb6+fvutuvy4f@grr.la>2015-12-28 11:33:12 +0000
commit2e00481ab7dfa35deaa980c3100a974349dc345f (patch)
treee4d9ac6e464cdc12b8ed4070487e52128332c0cc /lib/pry/config/lazy.rb
parent55f170ddb1801ac62cbeeefb004e1ed50816985b (diff)
downloadpry-2e00481ab7dfa35deaa980c3100a974349dc345f.tar.gz
make 'Pry::Config::Default' less of a special case by adding Pry::Config::Lazy
Diffstat (limited to 'lib/pry/config/lazy.rb')
-rw-r--r--lib/pry/config/lazy.rb26
1 files changed, 26 insertions, 0 deletions
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