aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module
Commit message (Collapse)AuthorAgeFilesLines
* Update delegate to use newer Ruby syntaxTodd Lynam2016-04-201-5/+2
| | | This commit updates `delegate` to use the keyword argument syntax added in Ruby 2. I left the `ArgumentError` when `to` is missing, because it better explains how to correctly use `delegate`. We could instead rely on the default `ArgumentError` that would be raised if `to` were a required keyword argument.
* fixed spelling in the attribute_accessors docuTorsten Braun2016-03-231-1/+1
| | | mattr_writer to mattr_reader
* fixed spellin in the mattr_reader documentationTorsten Braun2016-03-231-1/+1
| | | renamed cattr_reader to mattr_reader
* 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'.
* 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)`.
* :arrow_left: indentationAkira Matsuda2016-01-281-2/+2
| | | | [ci-skip]
* 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-171-0/+140
| | | | class and module variables that live per-thread
* Don't leak Object constants in core_ext/module/qualified_constGenadi Samokovarov2015-12-161-12/+30
|
* Minor fix in Module#mattr_reader documentationYuri Kasperovich2015-11-091-1/+1
|
* 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.
* Add Module#remove_possible_singleton_methodAndrew White2015-10-211-0/+7
| | | | | 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 #21302 from theunraveler/delegate_reserved_argument_namesSean Griffin2015-10-201-5/+6
|\ | | | | ActiveSupport: Fixing issue when delegating to methods named "block", "args", or "arg"
| * Fixing issue when delegating to methods named "block", "args", or "arg"Jake Bell2015-08-191-5/+6
| |
* | Regex fix for mattr_accessor validationAliaksandr Buhayeu2015-10-011-2/+2
| | | | | | | | | | Change ^ and $ operators to \A and \z to prevent code injection after the line breaks
* | Correcting `NameError` error message in `mattr_reader` method. Since this ↵amitkumarsuroliya2015-09-191-2/+2
|/ | | | | | commit https://github.com/rails/rails/commit/7dfbd91b0780fbd6a1dd9bfbc176e10894871d2d, `NameError` includes attribute_name also in error message [ci skip]
* Only invoke the default block for mattr_accessor once so that it does not ↵Lachlan Sylvester2015-08-071-1/+1
| | | | cause issues if it is not idempotent
* Freeze string literals when not mutated.schneems2015-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* adding brackets to array in docsJulio Lopez2015-07-071-1/+1
|
* Clearify that alias_method_chain is deprecatedPrem Sichanugrist2015-04-221-0/+3
| | | | | This was not clear on the API documentation that the method was deprecated in a982a42d766169c2170d7f100c2a5ceb5430efb1.
* Fix typos and improve the documentationJon Atack2015-04-151-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a squash of the following commits, from first to last: - Fix minor, random things I’ve come across lately that individually did not seem worth making a PR for, so I saved them for one commit. One common error is using “it’s” (which is an abbreviation of “it is”) when the possessive “its” should be used for indicating possession. - Changes include the name of a test, so remove the `[skip ci]` (thanks @senny). - Line wrap the changes at 80 chars and add one more doc fix. - Add a missing line wrap in the Contributing to Ruby on Rails Guide. - Line wrap the `TIP` section in the Contributing to Ruby on Rails Guide as well. Rendering the guide locally with `bundle exec rake guides:generate` did not show any change in on-screen formatting after adding the line wrap. The HTML generated is (extra line added to illustrate where the line wrap takes place): <div class="info"><p>Please squash your commits into a single commit when appropriate. This simplifies future cherry picks and also keeps the git log clean.</p></div> - Squash commits.
* [ci skip] Replace `query methods` with `a predicate`yui-knk2015-03-311-1/+1
|
* Remove circular requireRafael Mendonça França2015-03-272-4/+0
|
* Missing require 'active_support/deprecation'Akira Matsuda2015-03-272-0/+4
|
* Deprecate alias_method_chain in favour of Module#prependKir Shatrov2015-03-221-0/+2
| | | …as discussed #19413
* Some documentation edits [ci skip]Robin Dupret2015-03-051-3/+3
| | | | | | * Fix a few typos * Wrap some lines around 80 chars * Rephrase some statements
* Merge pull request #19131 from ↵Yves Senn2015-02-281-1/+1
|\ | | | | | | | | tgxworld/reduce_allocated_memory_in_module_delegate Reduce allocated memory for Module#delegate.
| * Reduce allocated memory for Module#delegate.Guo Xiang Tan2015-03-011-1/+1
| |
* | [ci skip] Add code examples for Module#anonymous? documentationAnton Davydov2015-02-281-0/+7
|/
* Revert 88d08f2ec9f89ba431cba8d0c06ac9ebc204bbbbRafael Mendonça França2015-02-111-12/+24
| | | | | | | This caused a performance regression since we were decided to do the nil check in run time not in the load time. See https://github.com/rails/rails/pull/15187#issuecomment-71760058
* adding documentation for 'remove_possible_method' and 'redefine_method' [ci ↵George Millo2015-01-051-0/+3
| | | | skip]
* Remove extra class_eval for Ruby 1.9Carlos Antonio da Silva2015-01-041-5/+2
|
* remove files which is dependent on ruby1.9 as we do not support Ruby1.9Kuldeep Aggarwal2015-01-041-11/+3
| | | | | Conflicts: activerecord/lib/active_record/attribute_methods/read.rb
* Replace `#=>` with `# =>` [ci skip]claudiob2014-12-171-1/+1
| | | | | | | | @rafaelfranca suggested in f7c7bcd9 that code examples should display the result after `# =>` and not after `#=>`. This commit replaces *all* the occurrences of `#=>` in the code documentation (mostly added by me :sob:) with the suggested `# =>`.
* English fix [ci skip]George Millo2014-12-121-1/+1
|
* doc added for `writer` method in `alias_method_chain`[ci skip]Kuldeep Aggarwal2014-10-041-2/+2
|
* Delegation works with reserved words passed to `:to`Agis-2014-09-191-1/+9
| | | | Fixes #16956.
* Fix confusing exception in ActiveSupport delegationVladimir Yarotsky2014-05-201-25/+13
|
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2014-02-091-1/+2
|\ | | | | | | | | | | | | Conflicts: guides/source/active_record_validations.md guides/source/api_documentation_guidelines.md guides/source/configuring.md
| * Fix grammar of internal comment and modify it's locationZachary Scott2014-02-091-1/+2
| |
* | fix typo and indent. [ci skip]Yves Senn2014-01-301-1/+1
| |
* | define the delegate methods on one line. fixes #13724Aaron Patterson2014-01-161-20/+22
| | | | | | | | sup haters