[Rails-core] Perfomance improvement

2016-05-14 Thread Dmitry Gautsel
Hi. What do you think about these changes: #current_behaviourdef ordinal(number) abs_number = number.to_i.abs if (11..13).include?(abs_number % 100) "th" else case abs_number % 10 when 1; "st" when 2; "nd" when 3; "rd" else"th" end endend #new beha

Re: [Rails-core] ActiveSupport Hash#dup

2016-04-30 Thread Dmitry Gautsel
I have found "test_deep_merge_on_indifferent_access". However there is no test for except method for these cases. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an e

Re: [Rails-core] ActiveSupport Hash#dup

2016-04-30 Thread Dmitry Gautsel
Hi, Jeremy. It seemed to be a good idea, but then I realized that it is actually not that good. Because: h={'test' => 123, ttt: 1234} # => {"test"=>123, :ttt=>1234} h=h.with_indifferent_access# => {"test"=>123, "ttt"=>1234} h.except(:ttt)

[Rails-core] Little refactoring for performance

2016-04-27 Thread Dmitry Gautsel
Hi all. What do you think about this changes https://github.com/rails/rails/compare/master...lvl0nax:am_refactoring?expand=1 Benchmark points 1) gsub => chomp str = 'some_test' Benchmark.ips do |x| x.report("chomp") { str.chomp('_test') } x.report("gsub") { str.gsub(/_test$/, '') } x.com

[Rails-core] ActiveSupport Hash#dup

2016-04-26 Thread Dmitry Gautsel
Hi all. What do you think about this fix: Hash#dup => Hash[hash] For example: 1) Hash#except method: class Hash # current behavior def except(*keys) dup.except!(*keys) end # new behavior def except2(*keys) Hash[self].except!(*keys) end def except!(*keys) keys.ea

[Rails-core] Little performance fix.

2016-04-24 Thread Dmitry Gautsel
Hi all. I have read activesupport module and found little issue. class Array # current behaviour def split(value = nil) if block_given? inject([[]]) do |results, element| if yield(element) results << [] else results.last << element end

[Rails-core] little improvements for active_model

2016-04-18 Thread Dmitry Gautsel
Hi all. What do you think about little improvements listed below? before: { error: message }.merge(options.except(*CALLBACKS_OPTIONS + MESSAGE_OPTIONS)) after: { error: message }.merge*!*(options.except(*CALLBACKS_OPTIONS + MESSAGE_OPTIONS)) before: matchers.map { |method| method.match(m