Class: Konstructor::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/konstructor/factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Factory



4
5
6
7
8
# File 'lib/konstructor/factory.rb', line 4

def initialize(klass)
  @klass = klass
  @konstructor_names = []
  @next_method_is_konstructor = false
end

Instance Method Details

#declare(new_names) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/konstructor/factory.rb', line 10

def declare(new_names)
  if new_names.empty?
    @next_method_is_konstructor = true
  else
    @next_method_is_konstructor = false
    process_new_names(new_names)
  end
end

#declared?(name) ⇒ Boolean

once method is a konstructor, it is always a konstructor, this differs from the way private, protected works, if overriding method isn’t repeatedly marked as private it becomes public



22
23
24
# File 'lib/konstructor/factory.rb', line 22

def declared?(name)
  declared_in_self?(name) || declared_in_superclass?(name)
end

#method_added_to_klass(name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/konstructor/factory.rb', line 26

def method_added_to_klass(name)
  name = name.to_sym

  if @next_method_is_konstructor
    @next_method_is_konstructor = false
    @konstructor_names << name
    define(name)
  elsif declared?(name)
    define(name)
  end
end