Class: AbstractInterface::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_us/abstract_interface.rb

Instance Method Summary collapse

Constructor Details

#initialize(constant, interface) ⇒ Interface

Returns a new instance of Interface.



4
5
6
7
# File 'lib/ruby_us/abstract_interface.rb', line 4

def initialize constant, interface
  @constant = constant
  @interface = interface
end

Instance Method Details

#define_method(method_name, &block) ⇒ Object



9
10
11
12
13
# File 'lib/ruby_us/abstract_interface.rb', line 9

def define_method method_name, &block
  @constant.module_eval do
    define_method method_name, &block
  end if block_given?
end

#define_singleton_method(method_name, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby_us/abstract_interface.rb', line 15

def define_singleton_method method_name, &block
  if block_given?
    if @constant.is_a? Class
      @constant.class_eval do
        define_singleton_method method_name, &block
      end
    elsif @constant != interface
      @constant::SingletonMethods.module_eval do
        define_method method_name, &block
      end
    end
  end
end