Sha256: d1301703c1e8eedc61781dc96bcf8f760b934efd167536db88f4020ca61159f4

Contents?: true

Size: 699 Bytes

Versions: 5

Compression:

Stored size: 699 Bytes

Contents

module Nyanko
  module Helper
    class << self
      def define(class_name, &block)
        prefix = UnitProxy.generate_prefix(class_name)
        define_methods_with_prefix(prefix, &block)
      end

      def define_methods_with_prefix(prefix, &block)
        define_methods(&block).each do |name|
          change_method_name(name, "#{prefix}#{name}")
        end
      end

      def define_methods(&block)
        before = instance_methods(false)
        self.class_eval(&block)
        instance_methods(false) - before
      end

      def change_method_name(from, to)
        class_eval do
          alias_method to, from
          remove_method from
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nyanko-0.0.6 lib/nyanko/helper.rb
nyanko-0.0.5 lib/nyanko/helper.rb
nyanko-0.0.4 lib/nyanko/helper.rb
nyanko-0.0.3 lib/nyanko/helper.rb
nyanko-0.0.1 lib/nyanko/helper.rb