Sha256: 20fe5b1ad6a6aee66c999235b03d0fda67464bd1af3cd5431f37db99e3d019fd

Contents?: true

Size: 941 Bytes

Versions: 19

Compression:

Stored size: 941 Bytes

Contents

module BMC::Monkey
  extend ActiveSupport::Concern

  class_methods do
    def prepend_instances(&block)
      m = Module.new(&block)
      send(:prepend, m)
    end

    def prepend_class(&block)
      m = Module.new(&block)
      singleton_class.send(:prepend, m)
    end

    def prepend_instance_method(name, &block)
      check_instance_method_exist!(name)

      m = Module.new
      m.send(:define_method, name, &block)
      send(:prepend, m)
    end

    def prepend_class_method(name, &block)
      check_class_method_exist!(name)

      m = Module.new
      m.send(:define_method, name, &block)
      singleton_class.send(:prepend, m)
    end

    def check_instance_method_exist!(name)
      raise "instance method `#{name}` does not exist" unless instance_methods.include?(name)
    end

    def check_class_method_exist!(name)
      raise "class method `#{name}` does not exist" unless methods.include?(name)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bmc-1.6.1 app/libs/bmc/monkey.rb
bmc-1.6.0 app/libs/bmc/monkey.rb
bmc-1.5.1 app/libs/bmc/monkey.rb
bmc-1.5.0 app/libs/bmc/monkey.rb
bmc-1.4.3 app/libs/bmc/monkey.rb
bmc-1.4.2 app/libs/bmc/monkey.rb
bmc-1.4.1 app/libs/bmc/monkey.rb
bmc-1.4.0 app/libs/bmc/monkey.rb
bmc-1.3.5 app/libs/bmc/monkey.rb
bmc-1.3.4 app/libs/bmc/monkey.rb
bmc-1.3.3 app/libs/bmc/monkey.rb
bmc-1.3.2 app/libs/bmc/monkey.rb
bmc-1.3.1 app/libs/bmc/monkey.rb
bmc-1.3.0 app/libs/bmc/monkey.rb
bmc-1.2.1 app/libs/bmc/monkey.rb
bmc-1.2.0 app/libs/bmc/monkey.rb
bmc-1.1.0 app/libs/bmc/monkey.rb
bmc-1.0.1 app/libs/bmc/monkey.rb
bmc-1.0.0 app/libs/bmc/monkey.rb