aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string
Commit message (Collapse)AuthorAgeFilesLines
* [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
|
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-03-261-1/+1
|\ | | | | | | | | Conflicts: guides/source/4_0_release_notes.md
| * [ci skip] Add space after erb block.yui-knk2015-03-121-1/+1
| |
* | Doc fixes [ci skip]Islam Wazery2015-03-073-3/+3
|/
* [skip ci] Add documentation for String#is_utf8? methodAnton Davydov2015-02-281-0/+7
|
* Merge pull request #19121 from davydovanton/update-doc-for-removeYves Senn2015-02-281-2/+3
|\ | | | | | | Update documentation examples for String#remove [skip ci]
| * Update documentation examples for String#remove [skip ci]Anton Davydov2015-02-281-6/+7
|/
* Fix a backtracking problem in String#truncate_wordsHenrik Nygren2015-02-251-1/+1
| | | | Fixes #19070.
* Properly dump primitive-like AS::SafeBuffer strings as YAMLGodfrey Chan2015-02-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `coder.represent_scalar` means something along the lines of "Here is a quoted string, you can just add it to the output", which is not the case here. It only works for simple strings that can appear unquoted in YAML, but causes problems for e.g. primitive-like strings ("1", "true"). `coder.represent_object` on the other hand, means that "This is the Ruby-object representation for this thing suitable for use in YAML dumping", which is what we want here. Before: YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello" YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => true YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => false YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => 1 YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => 1.1 After: YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello" YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => "true" YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => "false" YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => "1" YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => "1.1" If we ever want Ruby to behave more like PHP or JavaScript though, this is an excellent trick to use ;)
* Merge pull request #14028 from uberllama/json_escape_commentsRafael Mendonça França2015-02-061-0/+5
|\ | | | | Amended json_escape comments
| * Amended json_escape comment to clarify that user-generated content must ↵Yuval Kordov2014-02-121-0/+5
| | | | | | | | still be html_escaped if being inserted ingot he DOM via JQuery's html() method.
* | Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 ↵Vipul A M2015-02-031-1/+0
| | | | | | | | onwards.