Module: Ripl::Rc::U

Extended by:
Anchor::Imp, Color::Imp, SqueezeHistory::Imp, StripBacktrace::Imp
Included in:
Ripl, Anchor, Color, CtrldNewline, EatWhites, LastException, MkdirHistory, Multiline, 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

squeeze_history

Methods included from StripBacktrace::Imp

cwd, home, snip, strip_backtrace

Methods included from Anchor::Imp

short_inspect

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
# 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
    end

    def disable
      self.disabled = true
    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}
        #{mod.name}.#{meth}
      end
    RUBY
  } + %w[enabled? disabled?].map{ |meth|
    <<-RUBY
      def #{snake_name}_#{meth}
        #{mod.name}.#{meth}
      end
    RUBY
  }).join("\n")
  module_eval(code)
end