Skip to content
Browse files

added Either#inspect

  • Loading branch information...
1 parent 7122ce2 commit b2319dd4adb6b9c2b16ebba1c93deb00cd28cbe0 @ms-ati committed Apr 29, 2012
Showing with 27 additions and 0 deletions.
  1. +20 −0 lib/rumonade/either.rb
  2. +7 −0 test/either_test.rb
View
20 lib/rumonade/either.rb
@@ -107,6 +107,11 @@ def ==(other)
def to_s
"Left(#{left_value})"
end
+
+ # @return [String] Returns a +String+ containing a human-readable representation of this object.
+ def inspect
+ "Left(#{left_value.inspect})"
+ end
end
# The right side of the disjoint union, as opposed to the Left side.
@@ -128,6 +133,11 @@ def ==(other)
def to_s
"Right(#{right_value})"
end
+
+ # @return [String] Returns a +String+ containing a human-readable representation of this object.
+ def inspect
+ "Right(#{right_value.inspect})"
+ end
end
# @param (see Left#initialize)
@@ -217,6 +227,11 @@ def map(lam = nil, &blk)
def to_s
"LeftProjection(#{either_value})"
end
+
+ # @return [String] Returns a +String+ containing a human-readable representation of this object.
+ def inspect
+ "LeftProjection(#{either_value.inspect})"
+ end
end
# Projects an Either into a Right.
@@ -293,6 +308,11 @@ def map(lam = nil, &blk)
def to_s
"RightProjection(#{either_value})"
end
+
+ # @return [String] Returns a +String+ containing a human-readable representation of this object.
+ def inspect
+ "RightProjection(#{either_value.inspect})"
+ end
end
end
end
View
7 test/either_test.rb
@@ -160,6 +160,13 @@ def test_to_s_for_left_and_right_and_their_projections
assert_equal "LeftProjection(Right(42))", Right(42).left.to_s
end
+ def test_inspect_for_left_and_right_and_their_projections
+ assert_equal "Left(\"error\")", Left("error").inspect
+ assert_equal "Right(\"success\")", Right("success").inspect
+ assert_equal "RightProjection(Left(\"error\"))", Left("error").right.inspect
+ assert_equal "LeftProjection(Right(\"success\"))", Right("success").left.inspect
+ end
+
def test_plus_concatenates_left_and_right_using_plus_operator
assert_equal Left("badworse"), Left("bad") + Right(1) + Left("worse") + Right(2)
assert_equal Left(["bad", "worse"]), Left(["bad"]) + Right(1) + Left(["worse"]) + Right(2)

0 comments on commit b2319dd

Please sign in to comment.
Something went wrong with that request. Please try again.