[#66678] [ruby-trunk - Feature #10481] Add "if" and "unless" clauses to rescue statements — alex@...
Issue #10481 has been updated by Alex Boyd.
3 messages
2014/12/04
[#66762] Re: [ruby-changes:36667] normal:r48748 (trunk): struct: avoid all O(n) behavior on access — Tanaka Akira <akr@...>
2014-12-10 0:44 GMT+09:00 normal <ko1@atdot.net>:
3 messages
2014/12/10
[#66851] [ruby-trunk - Feature #10585] struct: speedup struct.attr = v for first 10 attributes and struct[:attr] for big structs — funny.falcon@...
Issue #10585 has been updated by Yura Sokolov.
3 messages
2014/12/15
[#67126] Ruby 2.2.0 Released — "NARUSE, Yui" <naruse@...>
We are pleased to announce the release of Ruby 2.2.0.
8 messages
2014/12/25
[#67128] Re: Ruby 2.2.0 Released
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2014/12/25
I can't install it in any of our Ubuntu servers using rbenv:
[#67129] Re: Ruby 2.2.0 Released
— SHIBATA Hiroshi <shibata.hiroshi@...>
2014/12/25
> I can't install it in any of our Ubuntu servers using rbenv:
[ruby-core:66696] [ruby-trunk - misc #10560] confusion between x=x+y, x+=y, x.concat(y) and y.each{|z| x<<z}
From:
davidm@...
Date:
2014-12-04 17:11:59 UTC
List:
ruby-core #66696
Issue #10560 has been updated by David MacMahon.
I imagine that Python also lets one override the `+=` method. I think this is impossible on Ruby because I think it is the parser that interprets `a += b` to be `a = a + b`, so only the `#+` method will be called (with coercion) regardless of which way it was expressed in the code. This was the conclusion I reached after trying to add a `#+=` method to a class (in a C extension for MRI) and discovering that it was never called by `a += b`. FWIW, it was callable via `#send`.
Maybe this could become a feature request to allow `<OP>=` to be methods instead of just syntactic sugar?
----------------------------------------
misc #10560: confusion between x=x+y, x+=y, x.concat(y) and y.each{|z| x<<z}
https://bugs.ruby-lang.org/issues/10560#change-50296
* Author: Michal Papis
* Status: Assigned
* Priority: Normal
* Assignee: Zachary Scott
* Category: doc
* Target version: current: 2.2.0
----------------------------------------
while discussing a ticket I have noticed that there is no documentation for `+=`
I was expecting `+=` to behave as `concat` but instead it behaves as `x=x+y` which for every operation clones the array and updates the variable with new value so it behaves similarly to `x=x.dup.concat(y)` and is slightly faster, but using plane `x.concat(y)` is a lot faster from both `each<<` and `+=`
I would either like to get:
- updated docs that describe concept of `+=` and show the difference from `concat`
- or change `+=` to use `concat` which is faster - and add docs ;) (I would expect `+=` to use `concat` when available)
here is a test:
require 'benchmark'
rep = 10_000
Benchmark.bmbm do |x|
{
1..25 => [],
"a".."z" => "",
}.each do |base, storage|
base = base.to_a
basej = base
class_name = storage.class.to_s
x.report(class_name+'#concat') do
a = storage.dup
basej = base.join if storage == ""
rep.times { a.concat(basej) }
end
x.report(class_name+'#<<') do
a = storage.dup
basej = base.join if storage == ""
rep.times { base.each { |e| a << e } }
end
x.report(class_name+'#+=') do
a = storage.dup
basej = base.join if storage == ""
rep.times { a += basej }
end
x.report(class_name+'#dup.concat') do
a = storage.dup
basej = base.join if storage == ""
rep.times { a = a.dup.concat(basej) }
end
end
end
and here are results on my machine:
user system total real
Array#concat 0.000000 0.000000 0.000000 ( 0.001422)
Array#<< 0.020000 0.000000 0.020000 ( 0.014356)
Array#+= 1.270000 0.230000 1.500000 ( 1.498558)
Array#dup.concat 2.720000 0.190000 2.910000 ( 2.915701)
String#concat 0.000000 0.000000 0.000000 ( 0.001072)
String#<< 0.030000 0.000000 0.030000 ( 0.025828)
String#+= 0.130000 0.010000 0.140000 ( 0.135143)
String#dup.concat 0.210000 0.020000 0.230000 ( 0.227470)
--
https://bugs.ruby-lang.org/