aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
Commit message (Collapse)AuthorAgeFilesLines
* Fix `thread_mattr_accessor` thread-local variable namingMichael Ryan2016-03-111-2/+2
| | | | | | | | | | | | | | | | | The current implentation of `thread_mattr_accessor` is setting differently-named thread variables when defining class and instance writer methods, so the method isn't working as documented: Account.user = "DHH" Account.user # => "DHH" Account.new.user # => nil a = Account.new a.user = "ABC" # => "ABC" a.class.user # => "DHH" At this point `:attr_Account_user` and `:attr_Class_user` thread-local variables have been created. Modify the reader and writer methods to use the class name instead of 'Class'.
* Add missing require to tryRafael Mendonça França2016-03-111-0/+2
|
* Deprecate `Module.local_constants`yui-knk2016-03-011-0/+4
| | | | | After Ruby 1.9, we can easily get the constants that have been defined locally by `Module.constants(false)`.
* Show correct return types for examples [ci skip]Gert Goet2016-02-201-49/+49
|
* Add `#on_weekday?` method to `Date`, `Time`, and `DateTime`.Vipul A M2016-02-151-0/+5
|
* rename to 'second_to_last' and 'third_to_last'Brian Christian2016-02-101-4/+4
|
* allow Array.penultimate and Array.antepenultiate access methodsBrian Christian2016-02-091-0/+14
|
* 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).
* Don't publicize Kernel core extensionsGenadi Samokovarov2016-02-042-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a reaction to a [bug] we hit in web-console. The cause of it was a `Kernel` extension called `#console` that was public and was fighting over Railties with console block to be run on `rails console`. We solved it by making the method private. We did that through `module_function` so `::Kernel.console` can be invoked even in `BasicObject`. I'm proposing to make most of the core Active Support `Kernel` extensions `module_function` as well. Those are currently public and we are polluting every `Object` public interface with them. ```ruby >> Object.new.respond_to? :silence_warnings => true >> Object.new.respond_to? :with_warnings => true >> Object.new.respond_to? :enable_warnings => true >> Object.new.respond_to? :suppress => true `` Some extensions like `Kernel#class_eval` should be public, but most of them don't really need to be. [bug]: https://github.com/rails/web-console/issues/184
* :arrow_left: indentationAkira Matsuda2016-01-281-2/+2
| | | | [ci-skip]
* Fix nodoc to internal class error document some of themVipul A M2016-01-252-0/+3
| | | | | | | [ci skip] Fixes #20808 [Vipul A M & Julio Lopez]
* Document scoping issue with Time.use_zoneAndrew White2016-01-231-1/+17
| | | | | | | | | | | | | | | | The Time.use_zone method will only affect ActiveSupport::TimeWithZone instances created inside of the block passed to Time.use_zone. This could be confusing when fetching a model and then reading the attribute before the block and it not changing afterwards because Active Record caches the conversion from the database value. Since changing the behavior of Active Record to recreate the value on every attribute read is an expensive operation the best we can do is to document the issue. Fixes #23195. [ci skip]
* Fix - to_s(:db) on Numeric rangeAkshay Vishnoi2015-12-291-1/+5
|
* Merge pull request #22822 from maclover7/fix-22805Richard Schneeman2015-12-281-0/+1
|\ | | | | Add a missing require to ActiveSupport::NumericWithFormat
| * Add a missing require to ActiveSupport::NumericWithFormatJon Moss2015-12-281-0/+1
| |
* | Add support for Petabyte and Exabyte in number to human sizeAkshay Vishnoi2015-12-221-0/+2
|/
* Use CGI.escapeHTML for html escapeTakashi Kokubun2015-12-211-4/+2
|
* Fix documentation for mattr_accessor methodsJan Habermann2015-12-201-6/+6
|
* [ci skip] Revert most of ff851017Kasper Timm Hansen2015-12-181-2/+2
| | | We went back to `Thread.current[]` in 33e11e59.
* Revert "Use Thread.current.thread_variable_set/get insetad of the direct ↵David Heinemeier Hansson2015-12-181-4/+4
| | | | | | accessors" This reverts commit 301f43820562c6a70dffe30f4227ff0751f47d4f per @matthewd on https://github.com/rails/rails/pull/22630/files#r47997074
* [ci skip] Add `Thread.current` to match internalsKasper Timm Hansen2015-12-171-2/+2
| | | | | | | | We call the thread variable accessors on `Thread.current`, which matches Ruby's documentation: http://ruby-doc.org/core-2.2.0/Thread.html#method-i-thread_variable_get Fix these to stay `current` ( ͡° ͜ʖ ͡°)
* Clarify thread_mattr_accessor subclass behavior documentationNate Berkopec2015-12-171-8/+9
| | | | [ci skip]
* Copy-edit the Per Thread attribute accessor documentationRafael Mendonça França2015-12-171-3/+3
| | | | [ci skip]
* Use Thread.current.thread_variable_set/get insetad of the direct accessorsDavid Heinemeier Hansson2015-12-171-4/+4
|
* Fix typo in thread_mattr_accessor doco [ci skip]Nate Berkopec2015-12-171-1/+1
|
* Add thread_m/cattr_accessor/reader/writer suite of methods for declaring ↵David Heinemeier Hansson2015-12-172-0/+141
| | | | class and module variables that live per-thread
* Merge pull request #22556 from imanel/range_prependKasper Timm Hansen2015-12-161-10/+7
|\ | | | | Use Module.prepend instead of alias_method for Range#to_s
| * Use Module.prepend instead of alias_method for Range#to_sBernard Potocki2015-12-161-10/+7
| |
* | Don't leak Object constants in core_ext/module/qualified_constGenadi Samokovarov2015-12-161-12/+30
| |
* | delete code commented out (and replaced) in e93d0a5Tony Ta2015-12-151-1/+0
|/
* Test if each_object(singleton_class) works, since JRuby added it.Charles Oliver Nutter2015-11-231-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #22376. JRuby 9.0.5.0 will support ObjectSpace.each_object against a class's singleton class, since that's essentially just walking an internal subclasses structure we already maintain. This test was too narrow, requiring that each_object support an arbitrary class but only actually needing it to work against a class's singleton. This improves performance of Class.descendants by nearly two orders of magnitude when run against JRuby 9.0.5.0: ```ruby 5.times { puts Benchmark.measure { 100_000.times { Numeric.descendants } } } ``` Before: ``` 11.510000 0.140000 11.650000 ( 10.082384) 9.990000 0.020000 10.010000 ( 9.931233) 10.520000 0.040000 10.560000 ( 10.502978) 10.290000 0.030000 10.320000 ( 10.276027) 10.000000 0.030000 10.030000 ( 9.942429) ``` After: ``` 1.380000 0.040000 1.420000 ( 0.365850) 0.210000 0.000000 0.210000 ( 0.149574) 0.180000 0.020000 0.200000 ( 0.141094) 0.140000 0.000000 0.140000 ( 0.140634) 0.190000 0.010000 0.200000 ( 0.147962) ```
* Change Enumerable#sum to use inject(:sym) specificationT.J. Schuck2015-11-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Not only does this make for simpler, more obvious code, it's also more performant: require 'benchmark/ips' module Enumerable def old_sum(identity = 0, &block) if block_given? map(&block).old_sum(identity) else inject { |sum, element| sum + element } || identity end end def new_sum(identity = 0, &block) if block_given? map(&block).new_sum(identity) else inject(:+) || identity end end end summable = (1..100).to_a # sum is 5050 Benchmark.ips do |x| x.report("old_sum") { summable.old_sum } x.report("new_sum") { summable.new_sum } x.compare! end # Calculating ------------------------------------- # old_sum 10.674k i/100ms # new_sum 14.542k i/100ms # ------------------------------------------------- # old_sum 117.350k (± 7.1%) i/s - 587.070k # new_sum 154.712k (± 3.8%) i/s - 785.268k # # Comparison: # new_sum: 154712.1 i/s # old_sum: 117350.0 i/s - 1.32x slower More benchmarks [here](https://gist.github.com/tjschuck/b3fe4e8c812712376648), including summing strings and passing blocks. The performance gains are less for those, but this version still always wins.
* Merge pull request #22244 from pacso/time-days-in-yearAndrew White2015-11-101-0/+6
|\ | | | | Add days_in_year method to Time class
| * Add days_in_year methodJon Pascoe2015-11-101-0/+6
| |
* | Minor fix in Module#mattr_reader documentationYuri Kasperovich2015-11-091-1/+1
|/
* Merge pull request #21897 from swaathi/masterKasper Timm Hansen2015-11-071-2/+20
|\ | | | | Parameterize with options to preserve the case of string
| * 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 #21806 from kachick/fix-transformer-sizeEileen M. Uchitelle2015-11-072-4/+4
|\ \ | |/ |/| Return a sized Enumerator from Hash#transform_values{!}
| * Return a sized Enumerator from Hash#{transform_values{!}|transform_keys{!}}Kenichi Kamiya2015-09-292-4/+4
| |
* | Merge pull request #16357 from gchan/hwia-respects-to-hash-defaultSean Griffin2015-10-291-1/+1
|\ \ | | | | | | | | | | | | `HashWithIndifferentAccess.new` respects the default value or proc on objects that respond to `#to_hash`
| * | `HashWithIndifferentAccess.new` respects the default value or proc on ↵Gordon Chan2014-07-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | objects that respond to `#to_hash`. Builds on the work of #12550 where `.new` will convert the object (that respond to `#to_hash`) to a hash and add that hash's keys and values to itself. This change will also make `.new` respect the default value or proc of objects that respond to `#to_hash`. In other words, this `.new` behaves exactly like `.new_from_hash_copying_default`. `.new_from_hash_copying_default` now simply invokes `.new` and any references to `.new_from_hash_copying_default` are replaced with `.new`. Added tests confirm behavior.
* | | Make `Module#redefine_method` to keep method visibilityyui-knk2015-10-261-0/+13
| | | | | | | | | | | | | | | | | | | | | Before this commit `Module#redefine_method` always changes visibility of redefined method to `public`. This commit changes behavior of Module#redefine_method` to keep method visibility.
* | | [ci skip] Add more code examples for `Module#anonymous?` docsyui-knk2015-10-231-2/+4
| | | | | | | | | | | | | | | In later code examples, it is better to write how `Module#anonymous?` works.
* | | Change Integer#year to return a Fixnum instead of a Float to improve consistencyKonstantinos Rousis2015-10-221-1/+1
| | |
* | | Add Module#remove_possible_singleton_methodAndrew White2015-10-212-1/+17
| | | | | | | | | | | | | | | This is primarily to fix method redefinition warnings in class_attribute but may be of use in other places where we define singleton methods.
* | | 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.
* | | | Merge pull request #20038 from imanel/numeric_prependSean Griffin2015-10-202-33/+19
|\ \ \ \ | | | | | | | | | | Use Module.prepend instead of alias_method and unify behavior of all Numeric extensions
| * | | | Unify behavior of all Numeric extensions and use Module.prepend instead of ↵Bernard Potocki2015-05-282-33/+19
| | | | | | | | | | | | | | | | | | | | alias_method
* | | | | Merge pull request #21302 from theunraveler/delegate_reserved_argument_namesSean Griffin2015-10-201-5/+6
|\ \ \ \ \ | | | | | | | | | | | | ActiveSupport: Fixing issue when delegating to methods named "block", "args", or "arg"