aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string
Commit message (Collapse)AuthorAgeFilesLines
* `String#strip_heredoc` preserves frozennessJeremy Daer2018-02-171-1/+3
| | | | | | | | | | | | | | | | | | ```ruby "foo".freeze.strip_heredoc.frozen? # => true ``` Fixes the case where frozen string literals would inadvertently become unfrozen: ```ruby foo = <<-MSG.strip_heredoc la la la MSG foo.frozen? # => false !?? ```
* Rails 6 requires Ruby 2.4.1+Jeremy Daer2018-02-171-3/+4
| | | | | | Skipping over 2.4.0 to sidestep the `"symbol_from_string".to_sym.dup` bug. References #32028
* Mention about Ruby 2.4 Unicode case mappings in `mb_chars` example [ci skip] ↵Ryuta Kamizono2017-11-291-1/+3
| | | | | (#31275) https://www.ruby-lang.org/en/news/2016/09/08/ruby-2-4-0-preview2-released/
* [ci skip] Correct output for UpcaseDixit Patel2017-11-291-1/+1
|
* Update incorrect backtick usage in RDoc to teletypeT.J. Schuck2017-11-222-2/+2
| | | [ci skip]
* [Active Support] require_relative => requireAkira Matsuda2017-10-216-10/+10
| | | | This basically reverts 8da30ad6be34339124ba4cb4e36aea260dda12bc
* Remove obsolete documentation [ci skip]Max Felsher2017-10-191-3/+0
| | | | | Instructions to use `h` or `html_escape` in ERB templates were added to `actionpack/lib/action_view/template_handlers/erb.rb` in a1b0349 (Rails 2.1), but ERB has automatically escaped values since Rails 3.
* Clarify intentions around method redefinitionsMatthew Draper2017-09-011-3/+3
| | | | | | | | | Don't use remove_method or remove_possible_method just before a new definition: at best the purpose is unclear, and at worst it creates a race condition. Instead, prefer redefine_method when practical, and silence_redefinition_of_method otherwise.
* Update String#camelize to provide feedback when wrong option is passedRicardo Díaz2017-08-021-0/+2
| | | | | | | | | String#camelize was returning nil without any feedback when an invalid option was passed as parameter. This update makes the method to raises an ArgumentError when the option passed is invalid, similar to what Ruby does for String#downcase (and others) in 2.4.1. https://ruby-doc.org/core-2.4.1/String.html#method-i-downcase
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-1113-0/+13
|
* Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-0913-0/+13
|
* [Active Support] require => require_relativeAkira Matsuda2017-07-016-9/+9
|
* Use keyword arguments instead of hashRafael Mendonça França2017-03-281-4/+4
|
* Merge pull request #28480 from ↵Rafael Mendonça França2017-03-281-9/+19
|\ | | | | | | | | | | mubashirhanif/add_keep_id_suffix_option_to_humanize_new Add keep id suffix option to humanize new
| * Added options hash to titleize method and keep_id_suffix option to humanizeMubashir Hanif2017-03-211-9/+19
| | | | | | | | | | | | | | | | | | | | | | | | some documentation remove extra whitespace. Added id in the middle test case and corrected some testcases. Some Coding standard guidelines corrections as suggested by codeclimate. Some more corrections suggested by codeclimate.
* | :golf: else + if = elsifAkira Matsuda2017-01-171-10/+8
| |
* | There's no such moduleAkira Matsuda2017-01-051-4/+4
|/
* Remove deprecated separator argument from parameterizeAndrew White2016-11-141-5/+1
|
* Merge pull request #26905 from bogdanvlviv/docsAndrew White2016-11-132-3/+3
|\ | | | | Add missing `+` around a some literals.
| * Add missing `+` around a some literals.bogdanvlviv2016-10-272-3/+3
| | | | | | | | | | | | Mainly around `nil` [ci skip]
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-292-3/+3
|/
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* code gardening: removes redundant selfsXavier Noria2016-08-082-3/+3
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-062-4/+4
|
* applies new string literal convention in activesupport/libXavier Noria2016-08-0610-23/+23
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Missing require 'active_support/multibyte/unicode'Akira Matsuda2016-07-121-0/+1
|
* Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-181-1/+1
| | | | | | | | Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer.
* Add compatibility for Ruby 2.4 `to_time` changesAndrew White2016-04-231-1/+1
| | | | | | | | | | | | | | | In Ruby 2.4 the `to_time` method for both `DateTime` and `Time` will preserve the timezone of the receiver when converting to an instance of `Time`. Since Rails 5.0 will support Ruby 2.2, 2.3 and later we need to introduce a compatibility layer so that apps that upgrade do not break. New apps will have a config initializer file that defaults to match the new Ruby 2.4 behavior going forward. For information about the changes to Ruby see: https://bugs.ruby-lang.org/issues/12189 https://bugs.ruby-lang.org/issues/12271 Fixes #24617.
* Match `String#to_time`'s behaviour to rubySiim Liiser2016-04-041-1/+2
| | | | | | | | Previously `String#to_time` returned the midnight of the current date in some cases where there was no relavant information in the string. Now the method returns `nil` instead in those cases. Fixes #22958.
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2016-04-031-1/+1
|\
| * s/responsibilty/responsibility/Vipul A M2016-03-221-1/+1
| | | | | | | | | | | | s/symantically/semantically/ [ci skip]
* | Fix method String#upcase_firstbogdanvlviv2016-03-311-1/+3
| |
* | Add upcase_first methodGlauco Custódio2016-02-251-0/+7
|/
* drop array allocations on `html_safe`Aaron Patterson2016-02-081-1/+1
| | | | | | | | For better or worse, anonymous `*` args will allocate arrays. Ideally, the interpreter would optimize away this allocation. However, given the number of times we call `html_safe` it seems worth the shedding idealism and going for performance. This line was the top allocation spot for a scaffold (and presumably worse on real applications).
* Fix nodoc to internal class error document some of themVipul A M2016-01-251-0/+1
| | | | | | | [ci skip] Fixes #20808 [Vipul A M & Julio Lopez]
* Use CGI.escapeHTML for html escapeTakashi Kokubun2015-12-211-4/+2
|
* Parameterize with options to preserve case of stringSwaathi K2015-11-071-2/+20
| | | | | | | | | | | | | | | | | | | | | | | | Added test cases Using kwargs instead of three seperate functions Updated parameterize in transliterate.rb Updated parameterize in transliterate.rb Added deprecation warnings and updating RDoc+Guide Misspelled separtor. Fixed. Deprecated test cases and added support to parameterize with keyword parameters Squashing commits. Fixed test cases and added deprecated test cases Small changes to Gemfile.lock and CHANGELOG Update Gemfile.lock
* Merge pull request #19992 from greysteil/handle-invalid-utf8-in-html-escapeSean Griffin2015-10-201-2/+2
|\ | | | | | | Handle invalid UTF-8 strings when HTML escaping
| * Handle invalid UTF-8 strings when HTML escapingGrey Baker2015-06-081-2/+2
| | | | | | | | | | | | | | Use `ActiveSupport::Multibyte::Unicode.tidy_bytes` to handle invalid UTF-8 strings in `ERB::Util.unwrapped_html_escape` and `ERB::Util.html_escape_once`. Prevents user-entered input passed from a querystring into a form field from causing invalid byte sequence errors.
* | Applying right result of examples in ActiveSupport Multibyte [ci skip]amitkumarsuroliya2015-09-211-6/+4
| |
* | String#strip_heredocs doesn't need Object#tryVlado Cingel2015-09-191-2/+0
| | | | | | | | Call to Object#try was removed with this pull request https://github.com/rails/rails/pull/21596
* | Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-09-181-1/+1
|\ \
| * | s/JQuery/jQuery/Akira Matsuda2015-09-181-1/+1
| | | | | | | | | | | | [ci skip]
* | | Improve String#strip_heredocJuanito Fatas2015-09-121-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Saves about 6 MB, about 40% faster. **strip_heredoc.rb** ```ruby require "active_support/core_ext/object/try" require "get_process_mem" class String def strip_heredoc indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0 gsub(/^[ \t]{#{indent}}/, '') end end if ENV["MEASURE_MEMORY"] == "yes" mem = GetProcessMem.new GC.start GC.disable 10000.times do <<-MSG.strip_heredoc xhr and xml_http_request methods are deprecated in favor of `get :index, xhr: true` and `post :create, xhr: true` MSG end before = mem.mb after = mem.mb GC.enable puts "Before: #{before} MiB" puts "After: #{after} MiB" puts "Diff: #{after - before} MiB" end ``` **patched_strip_heredoc.rb** ```ruby require "active_support/core_ext/object/try" require "get_process_mem" class String def patched_strip_heredoc gsub(/^#{scan(/^[ \t]*(?=\S)/).min}/, "".freeze) end end if ENV["MEASURE_MEMORY"] == "yes" mem = GetProcessMem.new GC.start GC.disable 10000.times do <<-MSG.patched_strip_heredoc xhr and xml_http_request methods are deprecated in favor of `get :index, xhr: true` and `post :create, xhr: true` MSG end before = mem.mb after = mem.mb GC.enable puts "Before: #{before} MiB" puts "After: #{after} MiB" puts "Diff: #{after - before} MiB" end ``` **Before** ``` $ MEASURE_MEMORY=yes ruby strip_heredoc.rb Before: 44.73828125 MiB After: 44.7734375 MiB Diff: 0.03515625 MiB ``` **After** ``` $ MEASURE_MEMORY=yes ruby patched_strip_heredoc.rb Before: 37.9765625 MiB After: 38.015625 MiB Diff: 0.0390625 MiB ``` `44.7734375 - 38.015625 = 6.75` => **Saves about 6.75 MiB** **benchmark.rb** ```ruby require "benchmark/ips" require_relative "./strip_heredoc" require_relative "./patched_strip_heredoc" def original <<-MSG.strip_heredoc xhr and xml_http_request methods are deprecated in favor of `get :index, xhr: true` and `post :create, xhr: true` MSG end def patched <<-MSG.patched_strip_heredoc xhr and xml_http_request methods are deprecated in favor of `get :index, xhr: true` and `post :create, xhr: true` MSG end Benchmark.ips do |x| x.report("original") { original } x.report(" patched") { patched } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14] Calculating ------------------------------------- original 5.652k i/100ms patched 6.477k i/100ms ------------------------------------------------- original 54.076k (± 5.7%) i/s - 271.296k patched 74.557k (± 6.2%) i/s - 375.666k Comparison: patched: 74557.0 i/s original: 54076.4 i/s - 1.38x slower ``` => **About 38% faster** 1. Clone rails project `git clone git@github.com:rails/rails.git` 2. Apply this patch to `activesupport/lib/active_support/core_ext/string/strip.rb` 3. `cd activesupport` 4. run `rake` 5. And tests passed: ``` ➜ activesupport $ rake /Users/Juan/.rubies/ruby-2.2.2/bin/ruby -w -I"lib:test" "/Users/Juan/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_test_loader.rb" "test/**/*_test.rb" ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ......................................................................S. SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS Finished in 15.343004s, 214.2344 runs/s, 24902.4898 assertions/s. 3287 runs, 382079 assertions, 0 failures, 0 errors, 48 skips You have skipped tests. Run with --verbose for details. ```
* | | Fixed Time conversion example for UTC time zone [ci skip]Ronak Jangir2015-09-081-1/+1
|/ /
* | minor documentation improvement [ci skip]Sam Auciello2015-08-241-2/+2
| |
* | Merge pull request #21217 from myrridin/myrridin-documentation-updatesZachary Scott2015-08-121-2/+2
|\ \ | | | | | | [ci skip] Documentation: Switch around a common phrase for readability
| * | [ci skip] Switch around a common idiom for readabilityThomas Hart II2015-08-051-2/+2
| |/
* / String#freeze optimizationsschneems2015-07-301-1/+1
|/
* Speedup String#squishojab2015-04-121-2/+1
|