Sha256: 01380f89f58e4be1642974dfc3cb89a50c074b33639c75be7c1e99dcbce9a60d

Contents?: true

Size: 724 Bytes

Versions: 1

Compression:

Stored size: 724 Bytes

Contents

raise LoadError, "colored not loaded" unless Object.const_defined?(:Colored)

def Colored!
  String.class_eval do
    Colored.instance_methods.each do |m|
      undef_method m
      define_method(m) do |*args|
        Colored.instance_method(m).bind(self).call(*args)
      end
    end
  end
end

module Colored
  class << self
    def not!
      String.class_eval do
        colors = COLORS.keys
        (
          EXTRAS.keys - %w[clear] +
          colors +
          colors.map { |c| "on_#{c}" } +
          colors.product(colors).reject { |p| p.inject(:==) }.map { |p| p.join '_on_' }
        ).map(&:to_sym).each do |m|
          undef_method m
          alias_method m, :dup
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
colored-not-1.2.1 lib/colored/not.rb