Module: Kernel

Defined in:
lib/attest/core_ext/kernel.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject Also known as: old_method_missing



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/attest/core_ext/kernel.rb', line 30

def new_method_missing(name, *args, &block)
  original_error = nil
  begin
      old_method_missing(name, *args, &block) 
    return
  rescue NoMethodError => e
    original_error = e
  end
  private_method = false
  instance_variable = false
  private_methods.each do |meth|
    private_method = true if meth == name
  end
  instance_variable = true if instance_variable_defined?("@#{name}".to_sym)
  if private_method
    send(name, *args, &block)
  elsif instance_variable
    self.class.class_eval do
      attr_reader name.to_sym
    end
    send(name, *args, &block)
  else
    raise original_error
  end
end

Instance Method Details

#new_method_missing(name, *args, &block) ⇒ Object Also known as: method_missing



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/attest/core_ext/kernel.rb', line 4

def new_method_missing(name, *args, &block)
  original_error = nil
  begin
      old_method_missing(name, *args, &block) 
    return
  rescue NoMethodError => e
    original_error = e
  end
  private_method = false
  instance_variable = false
  private_methods.each do |meth|
    private_method = true if meth == name
  end
  instance_variable = true if instance_variable_defined?("@#{name}".to_sym)
  if private_method
    send(name, *args, &block)
  elsif instance_variable
    self.class.class_eval do
      attr_reader name.to_sym
    end
    send(name, *args, &block)
  else
    raise original_error
  end
end

#new_require(filename) ⇒ Object Also known as: require



32
33
34
35
36
37
# File 'lib/attest/core_ext/kernel.rb', line 32

def new_require(filename)
  current_attest_value = ENV["attest"]
  ENV["attest"] = nil
  old_require(filename)
  ENV["attest"] = current_attest_value
end