Class: Method::Probe

Inherits:
Object show all
Defined in:
lib/mega/methodprobe.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProbe

Returns a new instance of Probe.



84
85
86
# File 'lib/mega/methodprobe.rb', line 84

def initialize
  @ducks, @decoys = {}, {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(aSym, *args) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/mega/methodprobe.rb', line 92

def method_missing(aSym, *args)
  aSymStr = aSym.to_s

  # This will happen the first time
  @ducks[aSymStr] ||= [] #unless @ducks[aSymStr]
  @ducks[aSymStr] << args.collect { |a| "#{a.class}" }

  decoy = self.dup

  @decoys[aSymStr] ||= [] #unless @decoys[aSymStr]
  @decoys[aSymStr] << decoy

  # build proxy?
  #begin
  #  d = <<-HERE
  #    def self.#{aSymStr}(*args)
  #      # This will happen the subsequent times
  #      @ducks["#{aSymStr}"] << args.collect { |a| #{'"#{a.class}"'} }
  #      @ducks["#{aSymStr}"].uniq!
  #      decoy = self.dup
  #      @decoys["#{aSymStr}"] = [] unless @decoys["#{aSymStr}"]
  #      @decoys["#{aSymStr}"] << decoy
  #      decoy
  #    end
  #  HERE
  #  instance_eval d
  #rescue SyntaxError
  #  puts "This error may be avoidable by returning the failing duck type as the error message."
  #  raise
  #end

  decoy
end

Instance Attribute Details

#decoysObject (readonly)

Returns the value of attribute decoys.



82
83
84
# File 'lib/mega/methodprobe.rb', line 82

def decoys
  @decoys
end

#ducksObject (readonly)

Returns the value of attribute ducks.



82
83
84
# File 'lib/mega/methodprobe.rb', line 82

def ducks
  @ducks
end

Class Method Details

.duckcallObject



73
74
75
76
77
78
79
80
# File 'lib/mega/methodprobe.rb', line 73

def Probe.duckcall
  begin
    yield
  rescue TypeError => e
    self.send(e.message)
    retry
  end
end

Instance Method Details

#initialize_copy(from) ⇒ Object



88
89
90
# File 'lib/mega/methodprobe.rb', line 88

def initialize_copy(from)
  initialize
end