Module: Nyanko::Helper

Defined in:
lib/nyanko/helper.rb

Class Method Summary collapse

Class Method Details

.change_method_name(from, to) ⇒ Object



21
22
23
24
25
26
# File 'lib/nyanko/helper.rb', line 21

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

.define(unit_name, &block) ⇒ Object



4
5
6
7
# File 'lib/nyanko/helper.rb', line 4

def define(unit_name, &block)
  prefix = UnitProxy.generate_prefix(unit_name)
  define_methods_with_prefix(prefix, &block)
end

.define_methods(&block) ⇒ Object



15
16
17
18
19
# File 'lib/nyanko/helper.rb', line 15

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

.define_methods_with_prefix(prefix, &block) ⇒ Object



9
10
11
12
13
# File 'lib/nyanko/helper.rb', line 9

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