aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-01-08 11:20:56 +0100
committerYves Senn <yves.senn@gmail.com>2014-01-08 11:27:43 +0100
commita03fed88f780922e3a3ab7b22af945f29a711ae4 (patch)
tree40773043da47196d92e5ac49cdaf0dda59b3ce02 /activesupport
parent40a83d740fafddcb3cad3b2c2dbfa3c446338d12 (diff)
downloadrails-a03fed88f780922e3a3ab7b22af945f29a711ae4.tar.gz
rails-a03fed88f780922e3a3ab7b22af945f29a711ae4.tar.bz2
rails-a03fed88f780922e3a3ab7b22af945f29a711ae4.zip
Revert "Speedup String#to"
This reverts commit 2ef1fb2c455ca53a0c1e1768f50824926ce28bd3. As described in PR #13627 this commit broke functionality when passing a negative Fixnum to the `String#to` method: ```ruby assert_equal "hell", s.to(-2) ``` Before the revert, this failed with: ``` 1) Failure: StringAccessTest#test_#to_with_negative_Fixnum,_position_is_counted_from_the_end [test/core_ext/string_ext_test.rb:275]: Expected: "hell" Actual: nil ``` This revert is to keep the functionality on `master` working. If there is another way to get the performance benefit and keep the documented functionality we can add that. /cc @amatsuda @carlosantoniodasilva
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/string/access.rb2
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb2
2 files changed, 1 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index d94e1bfca2..6018fd9641 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -59,7 +59,7 @@ class String
# str.from(0).to(-1) # => "hello"
# str.from(1).to(-2) # => "ell"
def to(position)
- self[0, position + 1]
+ self[0..position]
end
# Returns the first character. If a limit is supplied, returns a substring
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index 196dd1bce6..d4f8ba8cdd 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -272,12 +272,10 @@ class StringAccessTest < ActiveSupport::TestCase
end
test "#to with negative Fixnum, position is counted from the end" do
- skip "functionality was broken with 2ef1fb2c455ca53a0c1e1768f50824926ce28bd3"
assert_equal "hell", "hello".to(-2)
end
test "#from and #to can be combined" do
- skip "functionality was broken with 2ef1fb2c455ca53a0c1e1768f50824926ce28bd3"
assert_equal "hello", "hello".from(0).to(-1)
assert_equal "ell", "hello".from(1).to(-2)
end