Created
November 2, 2011 03:03
-
-
Save athom/1332733 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Proxy | |
def initialize(target_object) | |
@object = target_object | |
# ADD MORE CODE HERE | |
@call_count = {} | |
end | |
attr_accessor :channel | |
def proxy_call(m, *args) | |
if @call_count[m].nil? | |
@call_count[m] = 1 | |
else | |
@call_count[m] += 1 | |
end | |
if args.empty? | |
result = @object.send(m) | |
else | |
result = @object.send(m,*args) | |
end | |
end | |
def channel | |
proxy_call(:channel) | |
end | |
def channel=(ch) | |
proxy_call(:channel=, *[ch]) | |
end | |
def power | |
proxy_call(:power) | |
end | |
def on? | |
proxy_call(:on?) | |
end | |
def messages | |
@call_count.keys | |
end | |
def called?(method) | |
@call_count.keys.include?(method) | |
end | |
def number_of_times_called(m) | |
(@call_count[m].nil?)? 0 : @call_count[m] | |
end | |
def upcase! | |
proxy_call(:upcase!) | |
end | |
def split | |
proxy_call(:split) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment