Skip to content

Commit

Permalink
Fixing Kernel.String, all specs passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarsa committed Aug 7, 2009
1 parent 2e40b9e commit dc8136d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 9 additions & 1 deletion kernel/common/kernel.rb
Expand Up @@ -54,7 +54,15 @@ def Array(obj)
module_function :Array

def String(obj)
Type.coerce_to(obj, String, :to_s)
if obj.is_a? String
return obj
elsif obj.respond_to?(:to_s)
coerced_str = obj.to_s
return coerced_str if coerced_str.is_a? String
raise TypeError, "Coercion error: obj.to_s did NOT return a String (was #{coerced_str.class})"
else
raise TypeError, "can't convert Object into String: #{obj.inspect}"
end
end
module_function :String

Expand Down
4 changes: 0 additions & 4 deletions spec/tags/frozen/core/kernel/String_tags.txt
@@ -1,5 +1 @@
incomplete:Kernel#String needs to be reviewed for spec completeness
fails:Kernel.String raises a TypeError if respond_to? returns false for #to_s
fails:Kernel.String raises a NoMethodError if #to_s is not defined but #respond_to?(:to_s) returns true
fails:Kernel#String raises a TypeError if respond_to? returns false for #to_s
fails:Kernel#String raises a NoMethodError if #to_s is not defined but #respond_to?(:to_s) returns true

0 comments on commit dc8136d

Please sign in to comment.