Module: Ripl::Rc::U
- Extended by:
- Anchor::Imp, Color::Imp, SqueezeHistory::Imp, StripBacktrace::Imp
- Included in:
- Ripl, Anchor, Color, CtrldNewline, EatWhites, EnsureAfterLoop, LastException, MkdirHistory, Multiline, MultilineHistory, MultilineHistoryFile, SqueezeHistory, StripBacktrace
- Defined in:
- lib/ripl/rc/squeeze_history.rb,
lib/ripl/rc/strip_backtrace.rb,
lib/ripl/rc/anchor.rb,
lib/ripl/rc/color.rb,
lib/ripl/rc/u.rb
Class Method Summary collapse
Methods included from SqueezeHistory::Imp
Methods included from StripBacktrace::Imp
cwd, home, snip, strip_backtrace
Methods included from Anchor::Imp
Methods included from Color::Imp
black, blue, color, colors, cyan, find_color, green, magenta, red, reset, white, yellow
Class Method Details
.included(mod) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ripl/rc/u.rb', line 6 def self.included mod mod.send(:include, Ripl::Rc) class << mod attr_accessor :disabled def enable self.disabled = false yield if block_given? ensure disable if block_given? end def disable self.disabled = true yield if block_given? ensure enable if block_given? end def enabled? !disabled end def disabled? !!disabled end end snake_name = mod.name[/::\w+$/].tr(':', ''). # remove namespaces gsub(/([A-Z][a-z]*)/, '\\1_').downcase[0..-2] code = (%w[enable disable].map{ |meth| <<-RUBY def #{meth}_#{snake_name} &block #{mod.name}.#{meth}(&block) end RUBY } + %w[enabled? disabled?].map{ |meth| <<-RUBY def #{snake_name}_#{meth} &block #{mod.name}.#{meth}(&block) end RUBY }).join("\n") module_eval(code) end |