Skip to content

Commit

Permalink
Finished!
Browse files Browse the repository at this point in the history
  • Loading branch information
elvinlucero committed Feb 13, 2013
1 parent 52c137d commit e0f2761
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .path_progress
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0,0,1,5,6,6,6,6,6,6,6,6,7,7,7,8,8,8,9,10,10,11,11,11,13,13,13,14,15,16,18,19,19,19,19,19,19,19,19,20,21,21,22,23,24,25,26,27,27,29,31,31,32,32,33,35,35,35,35,35,35,35,35,35,35,38,40,41,41,41,42,42,42,43,43,44,45,46,49,50,50,50,50,51,52,53,53,55,58,59,60,61,62,62,63,64,64,64,65,66,66,66,69,71,71,71,71,71,75,79,75,79,75,79,82,83,84,84,84,84,84,85,88,90,92,93,94,95,97,98,98,99,99,99,102,103,103,106,106,106,107,107,108,109,111,111,112,114,114,114,114,114,115,115,114,115,116,116,117,117,117,119,121,122,122,122,123,125,125,125,125,125,131,132,135,136,137,141,141,144,144,146,149,149,150,153,153,153,152,153,153,153,153,153,153,153,154,156,156,158,158,158,158,150,159,159,163,165,166,166,167,168,168,168,173,174,176,177,178,181,182,182,182,182,183,183,182,182,182,183,184,184,188,188,183,190,188,190,190,182,190,190,190,190,191,191,192,192,195,196,199,201,201,201,201,201,201,203,204,205,205,205,206,207,209,210,210,214,218,219,220,221,221,221,222,226,226,226,227,228,228,230,232,233,234,234,234,235,235,235,241,241,241,242,244,244,247,249,253,253,253,253,253,254,256,256,256,257,259,259,260,262,263,265
0,0,1,5,6,6,6,6,6,6,6,6,7,7,7,8,8,8,9,10,10,11,11,11,13,13,13,14,15,16,18,19,19,19,19,19,19,19,19,20,21,21,22,23,24,25,26,27,27,29,31,31,32,32,33,35,35,35,35,35,35,35,35,35,35,38,40,41,41,41,42,42,42,43,43,44,45,46,49,50,50,50,50,51,52,53,53,55,58,59,60,61,62,62,63,64,64,64,65,66,66,66,69,71,71,71,71,71,75,79,75,79,75,79,82,83,84,84,84,84,84,85,88,90,92,93,94,95,97,98,98,99,99,99,102,103,103,106,106,106,107,107,108,109,111,111,112,114,114,114,114,114,115,115,114,115,116,116,117,117,117,119,121,122,122,122,123,125,125,125,125,125,131,132,135,136,137,141,141,144,144,146,149,149,150,153,153,153,152,153,153,153,153,153,153,153,154,156,156,158,158,158,158,150,159,159,163,165,166,166,167,168,168,168,173,174,176,177,178,181,182,182,182,182,183,183,182,182,182,183,184,184,188,188,183,190,188,190,190,182,190,190,190,190,191,191,192,192,195,196,199,201,201,201,201,201,201,203,204,205,205,205,206,207,209,210,210,214,218,219,220,221,221,221,222,226,226,226,227,228,228,230,232,233,234,234,234,235,235,235,241,241,241,242,244,244,247,249,253,253,253,253,253,254,256,256,256,257,259,259,260,262,263,265,265,265,266,265,265,265,267,268,268,268,269,269,269,269,275,276,277,278
23 changes: 22 additions & 1 deletion about_proxy_object_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,33 @@
# of the Proxy class is given in the AboutProxyObjectProject koan.

class Proxy
attr_accessor :messages
def initialize(target_object)
@object = target_object
# ADD MORE CODE HERE
@messages = []
end

# WRITE CODE HERE
def method_missing(method_name, *args, &block)
if @object.respond_to?(method_name)
@messages << method_name
@object.send(method_name, *args, &block)
else
super(method_name, *args, &block)
end
end

def called?(method_name)
@messages.include?(method_name)
end

def number_of_times_called(method_name)
num = 0
@messages.each {|a| a == method_name ? num += 1 : next }

num
end

end

# The proxy object should pass the following Koan:
Expand Down
12 changes: 6 additions & 6 deletions about_to_str.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def to_s

def test_to_s_returns_a_string_representation
not_like_a_string = CanNotBeTreatedAsString.new
assert_equal __, not_like_a_string.to_s
assert_equal "non-string-like", not_like_a_string.to_s
end

def test_normally_objects_cannot_be_used_where_strings_are_expected
assert_raise(___) do
assert_raise(TypeError) do
File.exist?(CanNotBeTreatedAsString.new)
end
end
Expand All @@ -33,11 +33,11 @@ def to_str

def test_to_str_also_returns_a_string_representation
like_a_string = CanBeTreatedAsString.new
assert_equal __, like_a_string.to_str
assert_equal "string-like", like_a_string.to_str
end

def test_to_str_allows_objects_to_be_treated_as_strings
assert_equal __, File.exist?(CanBeTreatedAsString.new)
assert_equal false, File.exist?(CanBeTreatedAsString.new)
end

# ------------------------------------------------------------------
Expand All @@ -48,7 +48,7 @@ def acts_like_a_string?(string)
end

def test_user_defined_code_can_check_for_to_str
assert_equal __, acts_like_a_string?(CanNotBeTreatedAsString.new)
assert_equal __, acts_like_a_string?(CanBeTreatedAsString.new)
assert_equal false, acts_like_a_string?(CanNotBeTreatedAsString.new)
assert_equal true, acts_like_a_string?(CanBeTreatedAsString.new)
end
end

0 comments on commit e0f2761

Please sign in to comment.