Sha256: b617ac29f980588ec24780b4ba1e01bfb65797c7751e77701145877c5b0aec37

Contents?: true

Size: 697 Bytes

Versions: 3

Compression:

Stored size: 697 Bytes

Contents

module Nyanko
  module Helper
    class << self
      def define(unit_name, &block)
        prefix = UnitProxy.generate_prefix(unit_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

3 entries across 3 versions & 1 rubygems

Version Path
nyanko-0.0.9 lib/nyanko/helper.rb
nyanko-0.0.8 lib/nyanko/helper.rb
nyanko-0.0.7 lib/nyanko/helper.rb