Skip to content

Commit

Permalink
Interpolating a single string results in that string.
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Nov 9, 2019
1 parent bab72d1 commit 28ac4fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
3 changes: 1 addition & 2 deletions spec/std/string_spec.cr
Expand Up @@ -2516,8 +2516,7 @@ describe "String" do
it "of a single string" do
string = "hello"
interpolated = String.interpolation(string)
interpolated.should_not be(string)
interpolated.should eq(string)
interpolated.should be(string)
end

it "of a single non-string" do
Expand Down
8 changes: 2 additions & 6 deletions src/string.cr
Expand Up @@ -4438,15 +4438,11 @@ class String
# "#{value}" # same as String.interpolation(value)
# ```
#
# In this case the implementation just returns a new string with the contents
# of `value`.
# In this case the implementation just returns the same string.
#
# NOTE: there should never be a need to call this method instead of using string interpolation.
def self.interpolation(value : String)
String.new(value.bytesize) do |buffer|
buffer.copy_from(value.to_unsafe, value.bytesize)
{value.bytesize, value.size_known? ? value.size : 0}
end
value
end

# Implementation of string interpolation of a single non-string value.
Expand Down

0 comments on commit 28ac4fd

Please sign in to comment.