Commit message (Collapse) | Author | Age | Files | Lines | |
---|---|---|---|---|---|
* | Remove `Array#sum` method before override it | yui-knk | 2016-04-24 | 1 | -0/+2 |
| | | | | | | | To suppress warning ('warning: method redefined; discarding old sum') remove the method before override it. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com> | ||||
* | Ruby 2.4 Array#sum: fix non-numeric #sum feature detection | Jeremy Daer | 2016-04-19 | 1 | -1/+1 |
| | |||||
* | Ruby 2.4: compat with new Array#sum | Jeremy Daer | 2016-04-18 | 1 | -0/+14 |
| | | | | | | | | | | | | | | | | | | | | | Ruby 2.4 introduces `Array#sum`, but it only supports numeric elements, breaking our `Enumerable#sum` which supports arbitrary `Object#+`. To fix, override `Array#sum` with our compatible implementation. Native Ruby 2.4: %w[ a b ].sum # => TypeError: String can't be coerced into Fixnum With `Enumerable#sum` shim: %w[ a b ].sum # => 'ab' We tried shimming the fast path and falling back to the compatible path if it fails, but that ends up slower even in simple causes due to the cost of exception handling. Our only choice is to override the native `Array#sum` with our `Enumerable#sum`. | ||||
* | Change Enumerable#sum to use inject(:sym) specification | T.J. Schuck | 2015-11-19 | 1 | -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. | ||||
* | Allow Enumerable#pluck to take a splat. | Kevin Deisz | 2015-05-29 | 1 | -2/+9 |
| | | | | | | This allows easier integration with ActiveRecord, such that AR#pluck will now use Enumerable#pluck if the relation is loaded, without needing to hit the database. | ||||
* | Add Enumerable#pluck. | Kevin Deisz | 2015-05-28 | 1 | -0/+8 |
| | | | | Allows fetching the same values from arrays as from ActiveRecord associations. | ||||
* | Use include? instead of in? for Enumerable#without. | Juanito Fatas | 2015-03-02 | 1 | -1/+1 |
| | | | | [egilburg] | ||||
* | Add Enumerable#without | Todd Bealmear | 2015-03-01 | 1 | -0/+11 |
| | |||||
* | Return sized enumerator from Enumerable#index_by | Marc-Andre Lafortune | 2014-02-05 | 1 | -1/+1 |
| | |||||
* | Return sized enumerator from Batches#find_each | Marc-Andre Lafortune | 2014-02-05 | 1 | -1/+1 |
| | |||||
* | update AS/core_ext docs [ci skip] | Francesco Rodriguez | 2012-09-12 | 1 | -5/+6 |
| | |||||
* | Fix Range#sum optimized version | Alexey Vakhov | 2012-05-25 | 1 | -2/+6 |
| | | | | | | | | | | | | | | | | | | | | | | At 1bd4d1c67459a91415ee73a8f55d2309c0d62a87 was added Range#sum optimized version for arithmetic progressions. This improvment injected a defect with not integer range boundaries. The defect was fixed by e0adfa82c05f9c975005f102b4bcaebfcd17d241. The second commit really disabled optimization at all because in Ruby integer-valued numbers are instances of Fixnum and Bignum classes. We should #use is_a? (#kind_of?) method instead #instance_of? to check if value is numerical: 1.class # => Fixnum 1.instance_of?(Integer) # => false 1.is_a?(Integer) # => true -100_000_000_000.class # => Bignum -100_000_000_000.instance_of?(Integer) # => false -100_000_000_000.is_a?(Integer) # => true Moreover original implementation of Range#sum has a defect with reverse range boundaries. If the first boundary is less than the second range is empty. Current commit fixes and tests this case too. | ||||
* | removing unnecessary 'examples' noise from activesupport | Francesco Rodriguez | 2012-05-13 | 1 | -2/+2 |
| | |||||
* | String quotes and trailing spaces | Alexey Gaziev | 2012-04-29 | 1 | -1/+1 |
| | |||||
* | AS core_ext refactoring pt.2 | Alexey Gaziev | 2012-04-29 | 1 | -3/+6 |
| | |||||
* | AS core_ext refactoring | Alexey Gaziev | 2012-04-29 | 1 | -3/+6 |
| | |||||
* | remove Enumerable#each_with_object again | Sergey Nartimov | 2011-12-23 | 1 | -21/+0 |
| | | | | it come back occasionally in 367741ef | ||||
* | remove conflict marker | Vijay Dev | 2011-12-23 | 1 | -1/+0 |
| | |||||
* | Revert "Added Enumerable#pluck to wrap the common pattern of ↵ | Aaron Patterson | 2011-12-22 | 1 | -5/+20 |
| | | | | | | | | | | | | collect(&:method) *DHH*" This reverts commit 4d20de8a50d889a09e6f5642984775fe796ca943. Conflicts: activesupport/CHANGELOG.md activesupport/lib/active_support/core_ext/enumerable.rb activesupport/test/core_ext/enumerable_test.rb | ||||
* | remove Enumerable#each_with_object from core_ext as it is present in ruby 1.9 | lest | 2011-12-21 | 1 | -21/+0 |
| | |||||
* | Initial pass at removing dead 1.8.x code from Active Support. | José Valim | 2011-12-20 | 1 | -37/+0 |
| | | | | | | There are a bunch of other implicit branches that adds 1.8.x specific code that still needs to be removed. Pull requests for those cases are welcome. | ||||
* | Added Enumerable#pluck to wrap the common pattern of collect(&:method) *DHH* | David Heinemeier Hansson | 2011-12-02 | 1 | -0/+7 |
| | |||||
* | docs formatting changes | Vijay Dev | 2011-09-01 | 1 | -2/+2 |
| | |||||
* | Trivial optimization for Enumerable#each_with_object | Marc-Andre Lafortune | 2011-07-23 | 1 | -2/+2 |
| | |||||
* | Insure that Enumerable#index_by, group_by, ... return Enumerators | Marc-Andre Lafortune | 2011-07-23 | 1 | -0/+3 |
| | |||||
* | Make Enumerable#many? iterate only over what is necessary | Marc-Andre Lafortune | 2011-07-23 | 1 | -3/+10 |
| | |||||
* | Make Enumerable#many? not rely on #size | Marc-Andre Lafortune | 2011-07-23 | 1 | -2/+2 |
| | |||||
* | #many? uses count instead of select - a bit faster | Julius Markūnas | 2011-07-11 | 1 | -1/+1 |
| | |||||
* | Clarify comment by removing french reference ('a la'). Should improve ↵ | Ben Orenstein | 2011-03-05 | 1 | -1/+1 |
| | | | | readability for non-native english speakers. | ||||
* | speed up index_by by removing a lolinject | Aaron Patterson | 2010-10-01 | 1 | -4/+1 |
| | |||||
* | Deletes trailing whitespaces (over text files only find * -type f -exec sed ↵ | Santiago Pastorino | 2010-08-14 | 1 | -4/+4 |
| | | | | 's/[ \t]*$//' -i {} \;) | ||||
* | edit pass to apply API guideline wrt the use of "# =>" in example code | Xavier Noria | 2010-07-30 | 1 | -1/+2 |
| | |||||
* | Add Enumerable#exclude? to bring parity to Enumerable#include? and avoid if ↵ | David Heinemeier Hansson | 2009-12-14 | 1 | -0/+5 |
| | | | | !x.include?/else calls [DHH] | ||||
* | Enumerable#none? is not needed for Ruby >= 1.8.7 | Xavier Noria | 2009-11-09 | 1 | -9/+0 |
| | |||||
* | Remove unnecessary &block from Range#sum and add tests for (num..float).sum | Pratik Naik | 2009-08-09 | 1 | -1/+1 |
| | |||||
* | Optimize Range#sum only for integers [#2489] | José Valim | 2009-08-09 | 1 | -2/+3 |
| | |||||
* | Optimize Range#sum to use arithmetic progression when a block is not given ↵ | José Valim | 2009-08-09 | 1 | -0/+9 |
| | | | | | | [#2489]. Signed-off-by: Pratik Naik <pratiknaik@gmail.com> | ||||
* | Enumerable#sum now works will all enumerables, even if they don't respond to ↵ | Marc-Andre Lafortune | 2009-08-08 | 1 | -4/+2 |
| | | | | | | | | :size [#2489 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net> | ||||
* | Merge docrails | Pratik Naik | 2009-07-25 | 1 | -1/+1 |
| | |||||
* | Simplify Enumerable#each_with_object | Jeremy Kemper | 2009-03-21 | 1 | -4/+3 |
| | |||||
* | Enumerable#none? conforms to Ruby 1.8.7 behavior | Jeremy Kemper | 2008-11-19 | 1 | -3/+3 |
| | |||||
* | Update doc to make more sense | David Heinemeier Hansson | 2008-11-19 | 1 | -1/+1 |
| | |||||
* | Added Enumerable#none? to check that none of the elements match the block ↵ | Damian Janowski | 2008-11-19 | 1 | -0/+9 |
| | | | | | | [#1408 state:committed] Signed-off-by: David Heinemeier Hansson <david@loudthinking.com> | ||||
* | Don't shadow arg with block var | Jeremy Kemper | 2008-09-08 | 1 | -2/+2 |
| | |||||
* | Add each_with_object from 1.9 for a more convenient alternative to inject. | Adam Keys | 2008-09-03 | 1 | -1/+21 |
| | | | | | Signed-off-by: Michael Koziarski <michael@koziarski.com> [#962 state:committed] | ||||
* | Added block-handling to Enumerable#many? (Damian Janowski) [#452 state:resolved] | David Heinemeier Hansson | 2008-06-20 | 1 | -1/+3 |
| | |||||
* | Change Enumberal#several? to Enumberal#many? | David Heinemeier Hansson | 2008-06-13 | 1 | -1/+1 |
| | |||||
* | Merge branch 'master' of git@github.com:rails/rails | David Heinemeier Hansson | 2008-06-12 | 1 | -3/+14 |
|\ | |||||
| * | Rubinious: work around h[k] ||= v returning []= result instead of v | Jeremy Kemper | 2008-06-10 | 1 | -3/+14 |
| | | |||||
* | | Added Enumberable#several? to encapsulate collection.size > 1 [DHH] | David Heinemeier Hansson | 2008-06-12 | 1 | -0/+5 |
|/ |