Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112023-04-26T06:13:55ZRuby Issue Tracking System
Redmine Test - Feature #19618 (Open): hash#dig testshttps://bugs.ruby-lang.org/issues/196182023-04-26T06:13:55Zhdiwan415 (Hasan Diwan)
<p>diff --git a/spec/ruby/core/hash/hash_spec.rb b/spec/ruby/core/hash/hash_spec.rb<br>
index 2ccb483120..3b583b338b 100644<br>
--- a/spec/ruby/core/hash/hash_spec.rb<br>
+++ b/spec/ruby/core/hash/hash_spec.rb<br>
@@ -1,4 +1,4 @@<br>
-require_relative '../../spec_helper'<br>
+require_relative "../../spec_helper"</p>
<p>describe "Hash" do<br>
it "includes Enumerable" do<br>
@@ -6,9 +6,18 @@<br>
end<br>
end</p>
<p>+describe "Hash#dig" do</p>
<ul>
<li>it "handles nested hash" do</li>
<li>{ foo: { bar: { baz: 2 } } }.dig(:foo).should == { :bar => { :baz => 2 } }</li>
<li>{ foo: { bar: { baz: 2 } } }.dig(:foo, :bar).should == { :baz => 2 }</li>
<li>{ foo: { bar: { baz: 2 } } }.dig(:foo, :bar, :baz).should == 2</li>
<li>{ foo: { bar: { baz: 2 } } }.dig(:BAZ).should.nil?</li>
<li>end<br>
+end</li>
<li>
</ul>
<p>describe "Hash#hash" do<br>
it "returns a value which doesn't depend on the hash order" do</p>
<ul>
<li>{ 0=>2, 11=>1 }.hash.should == { 11=>1, 0=>2 }.hash</li>
</ul>
<ul>
<li>{ 0 => 2, 11 => 1 }.hash.should == { 11 => 1, 0 => 2 }.hash<br>
end</li>
</ul>
<p>it "returns a value in which element values do not cancel each other out" do<br>
@@ -26,9 +35,9 @@<br>
end</p>
<p>it "returns the same hash for recursive hashes" do</p>
<ul>
<li>h = {} ; h[:x] = h</li>
<li>h.hash.should == {x: h}.hash</li>
<li>h.hash.should == {x: {x: h}}.hash</li>
</ul>
<ul>
<li>h = {}; h[:x] = h</li>
<li>h.hash.should == { x: h }.hash</li>
<li>h.hash.should == { x: { x: h } }.hash
<a name="This-is-because-heqlx-h"></a>
<h1 >This is because h.eql?(x: h)<a href="#This-is-because-heqlx-h" class="wiki-anchor">¶</a></h1>
<a name="Remember-that-if-two-objects-are-eql"></a>
<h1 >Remember that if two objects are eql?<a href="#Remember-that-if-two-objects-are-eql" class="wiki-anchor">¶</a></h1>
<a name="then-the-need-to-have-the-same-hash"></a>
<h1 >then the need to have the same hash.<a href="#then-the-need-to-have-the-same-hash" class="wiki-anchor">¶</a></h1>
</li>
</ul>
<p>@@ -36,9 +45,9 @@<br>
end</p>
<p>it "returns the same hash for recursive hashes through arrays" do</p>
<ul>
<li>h = {} ; rec = [h] ; h[:x] = rec</li>
<li>h.hash.should == {x: rec}.hash</li>
<li>h.hash.should == {x: [h]}.hash</li>
</ul>
<ul>
<li>h = {}; rec = [h]; h[:x] = rec</li>
<li>h.hash.should == { x: rec }.hash</li>
<li>h.hash.should == { x: [h] }.hash
<a name="Like-above-because-heqlx-h"></a>
<h1 >Like above, because h.eql?(x: [h])<a href="#Like-above-because-heqlx-h" class="wiki-anchor">¶</a></h1>
</li>
</ul>
<p>end</p>
<p>@@ -47,7 +56,7 @@<br>
a = 1<br>
b = 2</p>
<ul>
<li>
<pre><code>eval('{a:, b:}.should == { a: 1, b: 2 }')
</code></pre>
</li>
</ul>
<ul>
<li>
<pre><code> eval("{a:, b:}.should == { a: 1, b: 2 }")
</code></pre>
end<br>
end<br>
end</li>
</ul>
<a name="adds-tests-forHashdig"></a>
<h1 >adds tests for.Hash#dig<a href="#adds-tests-forHashdig" class="wiki-anchor">¶</a></h1> Test - Bug #19186 (Open): test2https://bugs.ruby-lang.org/issues/191862022-12-06T01:25:49Zshugo (Shugo Maeda)
<p>Hello, this is a test issue.<br>
This is a second line with umlaut: ü</p> Test - Bug #19185 (Open): testhttps://bugs.ruby-lang.org/issues/191852022-12-06T01:24:24Zshugo (Shugo Maeda)
<p>hello, this is a test issue.<br>
This is a second line.</p> Ruby master - Feature #9807 (Open): String.new with blockhttps://bugs.ruby-lang.org/issues/98072014-05-06T11:22:07Zcitizen428 (Michael Kohl)citizen428@gmail.com
<p>After a discussion in our team chat today, I wondered if it would be a good idea to have a version of String.new that accepts a block and works as a string builder. Something like</p>
<pre><code>string = String.new("foo") do |s|
s << "bar"
end
string #=> "foobar"
</code></pre>
<p>If the argument is omitted an empty string would be passed to the block instead.</p>
<p>That could be a nice solution to avoid all the Array#join and "".tap hacks for string creation.</p> Ruby master - Feature #9804 (Open): File::CREATE as a synonym for File::CREAThttps://bugs.ruby-lang.org/issues/98042014-05-05T16:53:35Zalexeymuranov (Alexey Muranov)
<p>I would like to have <code>File::CREATE</code> as a synonym for <code>File::CREAT</code>.</p> Ruby master - Feature #9784 (Open): Alias URI#merge to URI#joinhttps://bugs.ruby-lang.org/issues/97842014-04-29T05:42:45Zplexus (Arne Brasseur)arne@arnebrasseur.net
<p>To make Pathname and URI more consistent, it would be great to have a <code>join</code> instance method that behaves like <code>Pathname#join</code>. This could be a simple alias of <code>URI#merge</code>.</p> Ruby master - Feature #9779 (Open): Add Module#descendentshttps://bugs.ruby-lang.org/issues/97792014-04-28T07:02:06Zshugo (Shugo Maeda)
<p>Now classes have links to their subclasses, so how about to add Module#descendents?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">X</span>
<span class="k">end</span>
<span class="k">class</span> <span class="nc">Y</span> <span class="o"><</span> <span class="no">X</span>
<span class="k">end</span>
<span class="k">class</span> <span class="nc">Z</span> <span class="o"><</span> <span class="no">Y</span>
<span class="k">end</span>
<span class="nb">p</span> <span class="no">X</span><span class="p">.</span><span class="nf">descendents</span> <span class="c1">#=> [X, Y, Z]</span>
<span class="k">module</span> <span class="nn">A</span>
<span class="k">end</span>
<span class="k">module</span> <span class="nn">B</span>
<span class="kp">include</span> <span class="no">A</span>
<span class="k">end</span>
<span class="k">module</span> <span class="nn">C</span>
<span class="kp">include</span> <span class="no">A</span>
<span class="k">end</span>
<span class="nb">p</span> <span class="no">A</span><span class="p">.</span><span class="nf">descendents</span> <span class="c1">#=> [A, C, B]</span>
</code></pre>
<p>One of my own use cases is to implement AspectJ like pointcut which matches all subclasses of the given class.</p>
<p>Considerations:</p>
<ul>
<li>Should the return value of Module#descendents include self?</li>
<li>Should the return value of Module#descendents include singleton classes?</li>
</ul>
<p>I attach a patch, where the return value includes both self and singleton classes.</p> Ruby master - Bug #9760 (Open): mkmf does not allow for linking against custom libraries when a s...https://bugs.ruby-lang.org/issues/97602014-04-19T22:15:47Zzanegray (Andrew DeMaria)ademariad@gmail.com
<p>Hi,</p>
<p>Hopefully the title is not confusing, but the short story is that mkmf outputs a makefile that first searches the default lib path before searching any user provided lib paths. This is not an issue until one tries to link against an included library whose version is different than a preexisting system library.</p>
<p>The issue cropped up while trying to install the rugged gem (libgit2 wrapper) and a full dialog on the issue can be found on github <a href="https://github.com/libgit2/rugged/issues/351" class="external">https://github.com/libgit2/rugged/issues/351</a>.</p>
<p>I was able to fix the issue with the attached patch (<a href="https://github.com/muff1nman/ruby/commit/a0c8bc32cfc11e61c5b9703bff243934c6509210" class="external">https://github.com/muff1nman/ruby/commit/a0c8bc32cfc11e61c5b9703bff243934c6509210</a>)</p> Ruby master - Feature #9725 (Open): Do not inspect NameError target object unless verbosehttps://bugs.ruby-lang.org/issues/97252014-04-10T22:19:37Zheadius (Charles Nutter)headius@headius.com
<p>At least once every few months, we get an error report of JRuby raising a memory error where MRI does not due to <code>NameError</code>'s <code>Message</code> object holding a reference to an object that's too large to inspect. I propose that this inspection of the target object should only be done in verbose mode.</p>
<a name="Background"></a>
<h2 >Background:<a href="#Background" class="wiki-anchor">¶</a></h2>
<p><code>NameError</code> is raised when a variable-like method call fails to find a defined method. The resulting exception is created with a hidden <code>NameError::Message</code> that holds the object in which the method could not be found.</p>
<p>When name error needs to render its message, such as when it bubbles out or when <code>#message</code> is called, it does <code>to_str</code> on the <code>NameError::Message</code>, which ends up inspecting the target object. If this object's inspect output is large (or infinite) it can end up consuming a large amount of memory.</p>
<a name="Problems"></a>
<h2 >Problems:<a href="#Problems" class="wiki-anchor">¶</a></h2>
<ul>
<li>If the amount of memory required to render a <code>NameError</code> exceeds available memory, a very confusing and misleading memory error can be raised instead.</li>
<li>If the target object is considered sensitive data, it will end up bubbling out through potentially untrustworthy code. It is an encapsulation flaw, basically.</li>
<li>A <code>NameError</code> that gets held in memory will also prevent GC of the object it references.</li>
</ul>
<a name="Solutions"></a>
<h2 >Solutions:<a href="#Solutions" class="wiki-anchor">¶</a></h2>
<ul>
<li>
<code>NameError</code> should not capture the target object.</li>
<li>
<code>NameError</code> should build a message based on the target object <em>at creation time</em>, and only include information useful to indicate the type of object.</li>
<li>(Optional) If verbose mode is set, <code>NameError</code> can just do what it does now.</li>
</ul> Ruby master - Misc #9724 (Open): Warnings in Ruby: allow per-file directives to i.e. suppress war...https://bugs.ruby-lang.org/issues/97242014-04-10T18:21:31Zshevegen (Robert A. Heiler)shevegen@gmail.com
<p>Hi,</p>
<p>A bit of intro.</p>
<p>I usually run all my ruby code with -w. I feel that it gives me some more security if the<br>
ruby parser does not have to think about ambiguous code.</p>
<p>Now this works perfect for my own code - I know what I have written, I know how to fix it,<br>
so my code runs fine.</p>
<p>Problem is other people who do not use the -w switch, and in doing so their stuff outputs<br>
a lot of warnings if I require their project and use them.</p>
<p>This is somewhat annoying and there is no real good way to fix it as far as I know.</p>
<p>Modifying $VERBOSE and setting it to nil is of no real help because it works globally.<br>
But I'd rather want something to be used on a per-file basis.</p>
<p>Would it be possible to enable something that could be used on a per file<br>
basis? Kernel.no_warnings, or Kernel.be_silent or something like this?</p> Ruby master - Feature #9686 (Open): Syntax for symbols used in hasheshttps://bugs.ruby-lang.org/issues/96862014-03-28T19:56:40Zsaschamayr (Sascha Mayr)mayr.sascha@gmail.com
<p>Symbols are often used literally as keys in hashes like this:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="p">{</span><span class="ss">foo: </span><span class="s1">'bar'</span><span class="p">}</span>
</code></pre>
<p>But acutally there is a little inconvenience when using the alternative <code>:"name"</code> literal syntax:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">string</span> <span class="o">=</span> <span class="s1">'foo'</span>
<span class="p">{</span><span class="ss">:"</span><span class="si">#{</span><span class="n">string</span><span class="si">}</span><span class="ss">"</span> <span class="o">=></span> <span class="s1">'bar'</span><span class="p">}</span>
</code></pre>
<p>It would be great if Ruby provided the possibility to write the second example like this:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">string</span> <span class="o">=</span> <span class="s1">'foo'</span>
<span class="p">{</span><span class="s2">"</span><span class="si">#{</span><span class="n">string</span><span class="si">}</span><span class="s2">"</span><span class="p">:</span> <span class="s1">'bar'</span><span class="p">}</span>
</code></pre>
<p>This would be logical, because you can write both syntaxes the same way when not using them in hashes.</p> Ruby master - Feature #9667 (Open): Optimization of __FILE__ and __dir__https://bugs.ruby-lang.org/issues/96672014-03-24T09:19:04Zsawa (Tsuyoshi Sawada)
<p>In the same spirit as the string literal followed by <code>freeze</code> is optimized, I think <code>__FILE__</code> and <code>__dir__</code> should be optimized. Currently, they return different object id each time they are called.</p>
<pre><code>__FILE__.object_id # => 70183725179420
__FILE__.object_id # => 70183725129020
...
</code></pre>
<p>I propose them to be optimized so that they are only created once per occurrence.</p>
<pre><code>__FILE__.object_id # => 70183725179420
__FILE__.object_id # => 70183725179420
...
</code></pre> Ruby master - Feature #9613 (Open): Warn about unsafe ossl ciphershttps://bugs.ruby-lang.org/issues/96132014-03-08T03:04:48Zzzak (zzak _)
<p>As of r45274, we now have sane whitelist of available OpenSSL ciphers. However, this patch breaks backwards compatibility for any apps that use any ciphers not whitelisted.</p>
<a name="Solution"></a>
<h2 >Solution<a href="#Solution" class="wiki-anchor">¶</a></h2>
<ul>
<li>Implement a new class: OpenSSL::SSL::Ciphers
<ul>
<li>This class defines a constant for every whitelisted cipher used by DEFAULT_PARAMS[:ciphers]</li>
<li>Any constant not found within this class should raise a warning and report to the user</li>
</ul>
</li>
<li>Add an OpenSSL::SSL::Configuration class
<ul>
<li>Designed to default to no compression, and no sslv2/v3</li>
<li>Used by DEFAULT_PARAMS[:options]</li>
<li>This class may contain helper methods such as: #compression_enabled?</li>
</ul>
</li>
</ul>
<a name="Pros"></a>
<h2 >Pros<a href="#Pros" class="wiki-anchor">¶</a></h2>
<ul>
<li>We don't break anything, without warning users first</li>
<li>Maintaining future whitelist ciphers is easier</li>
<li>Future unsupported/blacklist ciphers are already dismissed</li>
<li>Users are able to extend cipher lists to support their needs (by adding a constant to OpenSSL::SSL::Ciphers)</li>
</ul>
<a name="Concerns"></a>
<h2 >Concerns<a href="#Concerns" class="wiki-anchor">¶</a></h2>
<p>I have discussed this with Martin, and we'd like to open up this discussion for feedback. We're particularly concerned about backporting r45274 as it breaks compatibility. We should also consider:</p>
<ul>
<li>Do we backport both patches or just the warning?</li>
<li>Should we bother backporting deprecation warnings?
<ul>
<li>Since r45274 is not a security fix, do we consider this a bug?</li>
<li>Rails only introduces deprecation notices in new minor releases (ie: Ruby-2.2.0)</li>
</ul>
</li>
<li>r45274 is a major change that could break existing apps, even considering security</li>
</ul> Ruby master - Feature #9585 (Open): Add Object#in? to make ruby easier to readhttps://bugs.ruby-lang.org/issues/95852014-03-01T11:43:17Zsowieso (So Wieso)sowieso@dukun.de
<p>Please add an in? method to all objects, that allows the following:<br>
<code>4.in? 1,2,3,4 4.in? 1..4 "a".in? "abc" 7.in? 0..2, 5..8 3.in? small_numbers.select(&:odd?) =>true</code><br>
Background:<br>
Since my first steps in ruby it always bugs me, that using Array#include? to perform multiple checks in one line breaks symmetry, forces me to read backward and thus lets me stumble in the head. Ruby tries to be close to natural language, and therefore the subject should stand on the left side. Example:<br>
<code>if status == 1 if status == 1 or status == 2 if [1,2,127].include? status # breaks symmetry if status.in? 1, 2, 127 # better</code></p>
<p>Pros:<br>
‣ Nicer to read, no need to read the line backward (brings joy to writers and readers)<br>
‣ No new keyword<br>
‣ Breaks nothing</p>
<p>Cons:<br>
‣ One more method in Object<br>
‣ <code>"a".in? "abc", "def" vs "a".in? ["abc", "def"]</code> (implementation is yet an example)</p>
<p>Neutral:<br>
‣ Yet one more way to do it (isn't that ruby-style?)<br>
‣ Belongs to Object, as a comparison operator like ==, eql?, ===, nil?<br>
‣ “only cosmetics” vs elegance</p>
<p>Implementation for testing (you'd certainly find a less naive implementation):<br>
<code>class Object def in? *args raise ArgumentError if args.empty? args.any? {|a| a == self or a.include? self rescue false} end end</code><br>
This is related to <a href="https://bugs.ruby-lang.org/issues/3845" class="external">https://bugs.ruby-lang.org/issues/3845</a><br>
which was rejected for being an operator (even though the keyword already existed)</p> Ruby master - Feature #9557 (Open): Enumerator#next and Enumerator#peek with argumenthttps://bugs.ruby-lang.org/issues/95572014-02-23T09:14:18Zsawa (Tsuyoshi Sawada)
<p>It often happens that I want to move the current index of an enumerator by some arbitrary number <code>n</code>. <code>Enumerator#feed</code> takes the element as the argument, but that cannot be used if the enumerator has duplicate elements, or when I do not have information of a particular element to choose but just want to increment the index by some number. <code>Enumerator#next</code>, on the other hand, has a fixed value <code>1</code> to be incremented. It would be convenient if <code>Enumerator#next</code> takes an optional argument that represents the difference of the index to be incremented. The argument can be understood to be defaulted to <code>1</code> when absent.</p>
<p>Also, I often want to look not necessarily the current position, but some position away. It would be good if <code>Enumerator#peek</code> takes an optional argument that represents the positional difference to be peeked. The argument can be understood to be defaulted to <code>0</code> when absent.</p>
<pre><code>enum = [0, 1, 2, 3, 4, 5, 6, 7, 8].to_enum
enum.peek # => 0
enum.peek(0) # => 0
enum.peek(1) # => 1
enum.peek # => 0
enum.next # => 0
enum.next(1) # => 1
enum.next(2) # => 2
enum.peek # => 4
enum.peek(0) # => 4
enum.peek(1) # => 5
enum.peek # => 4
enum.next # => 4
enum.next(1) # => 5
enum.next(2) # => 6
peek # => 8
</code></pre> Ruby master - Feature #9556 (Open): Add HTTP#get block functionality to HTTP.gethttps://bugs.ruby-lang.org/issues/95562014-02-23T05:53:38Zsrawlins (Sam Rawlins)sam.rawlins@gmail.com
<p>This is kind of an alternative to <a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: make Net::HTTP.get_print not only to $stdout but to an IO as a parameter (Open)" href="https://bugs.ruby-lang.org/issues/9527">#9527</a>.</p>
<p>HTTP#get can be passed a block. The shortcut method, HTTP.get, however, cannot. This patch adds such functionality.</p>
<p>This allows someone to be able to write the response of a GET, in fragments, without dealing directly with Net::HTTPResponse, like the request in <a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: make Net::HTTP.get_print not only to $stdout but to an IO as a parameter (Open)" href="https://bugs.ruby-lang.org/issues/9527">#9527</a>:</p>
<pre><code>File.open('result.zip', 'wb') {|f|
Net::HTTP.get('www.example.com', '/file.zip') do |chunk|
f.write chunk
end
}
</code></pre>
<p>This patch includes that example as documentation, and a test. It is attached, and available at: <a href="https://github.com/srawlins/ruby/compare/add-block-to-http-get" class="external">https://github.com/srawlins/ruby/compare/add-block-to-http-get</a></p> Ruby master - Feature #9553 (Open): Make argument validation routine of a method an objecthttps://bugs.ruby-lang.org/issues/95532014-02-22T07:02:45ZAnonymous
<p>Ruby methods have their acceptable argument configurations specified by special syntax. As argument fields has gotten more complex, simple <code>#arity</code> is no longer enough to capture the type of the argument field. I suggest making this argument validation routine (so far defined by special syntax) introspectible, and reusable for the purposes of metaprogramming. One possibility would be to have eg. <code>ArgumentValidator</code> and/or <code>UnboundArgumentValidator</code> objects just like we have method and unbound method objects. Then eg. <code>Method#argity</code> / <code>Proc#argity</code> would return that <code>ArgumentValidator</code> or <code>UnboundArgumentValidator</code>. The purpose of this post is not to suggest the final solution, but to bring attention to the problem of non-oo nature of built-in argument validation and the growing need to do something about that.</p> Ruby master - Feature #9527 (Open): make Net::HTTP.get_print not only to $stdout but to an IO as ...https://bugs.ruby-lang.org/issues/95272014-02-18T10:59:48Zbdimych (Dmitry Bolshakov)bdimych@narod.ru
<p>e.g.</p>
<p>url = '<a href="http://server/path/large-file.zip" class="external">http://server/path/large-file.zip</a>'<br>
fh = File.new(File.basename(url), 'wb')<br>
Net::HTTP.get_print(URI(url), fh)<br>
fh.close</p>
<p>imho looks good</p> Ruby master - Feature #9522 (Open): Float( "NaN" ), Float( "Infinity" )https://bugs.ruby-lang.org/issues/95222014-02-16T05:36:59ZAnonymous
<p>I have noticed that 0.0 / 0.0 returns NaN, but Float( "#{0.0 / 0.0}" ),<br>
or simply Float( "NaN" ) does not return Float::NAN, failing instead.<br>
To me, even inclusion of NaN among floats is somewhat questionable, but<br>
since it's there, Float( "NaN" ) needs to be discussed. Same would go<br>
for Float( "Infinity" ).</p>
<p>The issue here might be that not all the users are aware that NaN and<br>
Infinity have special meaning in the context of floats, and they might<br>
use these strings inadvertantly without actually meaning a Float.</p> Ruby master - Misc #9516 (Open): Consolidate all deprecation messages to one or more helper methodshttps://bugs.ruby-lang.org/issues/95162014-02-13T17:11:56Zenebo (Thomas Enebo)tom.enebo@gmail.com
<p>I was examining this blog entry: <a href="http://batsov.com/articles/2014/02/05/a-list-of-deprecated-stuff-in-ruby/" class="external">http://batsov.com/articles/2014/02/05/a-list-of-deprecated-stuff-in-ruby/</a> and I wanted to add these warning in JRuby. I thought it would be nice if I could make a higher level construct (e.g. @RubyDeprecated(use="Dir.exist?")) but then realized MRI does not consistently have the same warning string formats:</p>
<p>"Dir.exists? is a deprecated name, use Dir.exist? instead"<br>
"GDBM#index is deprecated; use GDBM#key"<br>
"Zlib::GzipReader#bytes is deprecated; use #each_byte instead"</p>
<p>Some helper methods could make these consistent and then I could make the higher level abstraction in JRuby as well. Since these are warnings I might still make an abstraction and let JRuby be a little inconsistent but I thought I would pass this idea along.</p> Ruby master - Feature #9515 (Open): `IO.each` and `CSV.each`https://bugs.ruby-lang.org/issues/95152014-02-12T16:16:41Zsawa (Tsuyoshi Sawada)
<p>In <code>IO</code> class, there are pairs of a class method and an instance method with related function:</p>
<ul>
<li>
<code>IO.read</code> and <code>IO#read</code>
</li>
<li>
<code>IO.write</code> and <code>IO#write</code>
</li>
<li>
<code>IO.foreach</code> and <code>IO#each</code> (or its alias <code>IO#each_line</code>)</li>
</ul>
<p>For consistency, please make <code>IO.each</code> an alias for <code>IO.foreach</code>.</p>
<p>The same thing can be said for <code>CSV.each</code>.</p> Ruby master - Feature #9445 (Open): Support emitting 1.9 Symbol keyword Hash syntax when pretty p...https://bugs.ruby-lang.org/issues/94452014-01-24T02:16:43Zpostmodern (Hal Brodigan)postmodern.mod3@gmail.com
<p>Ruby 1.9 first introduced support for keyword Hash syntax for simple Symbol keys. However, Hash#inspect and pp do not emit the same syntax when printing Symbol keys. This patch adds support for "foo: " syntax to the pp_hash method, iff the key is a Symbol and does not contain any spaces or special characters. While the patch is probably not perfect, I hope to start a discussion.</p> Ruby master - Feature #9402 (Open): A syntax to specify the default value of a hashhttps://bugs.ruby-lang.org/issues/94022014-01-12T13:00:05Zalexeymuranov (Alexey Muranov)
<p>I propose the following syntax to specify the default value of a hash:</p>
<pre><code>h = { => 0, :a => 1, :b => 2 }
h[:a] # => 1
h[:c] # => 0
</code></pre> Ruby master - Feature #9401 (Open): Yet another syntax for literal anonymous functions (lambdas)https://bugs.ruby-lang.org/issues/94012014-01-12T10:44:54Zalexeymuranov (Alexey Muranov)
<p>Please do not be angry at me and just close this proposal if it does not look interesting. It comes from my aesthetic dissatisfaction with the <code>->(x){ ... }</code> literal anonymous function notation and from my amateurish interest in lambda calculus.</p>
<p>Here is a yet another syntax for literal anonymous functions (lambdas) that i propose:</p>
<pre><code>f = {\ x => x*x }
f[1] # => 1
f[2] # => 4
</code></pre>
<p>It looks a bit like a hash on purpose: i think that a hash is a "function in extension" and a lambda is a "function in intension" (see, for example, in <a href="http://www.classes.cs.uchicago.edu/archive/2004/spring/15300-1/docs/lambda-intro.pdf" class="external">these notes</a>). The backslash stands for "lambda", like in Haskell.</p> Ruby master - Feature #9400 (Open): Respect constant lookup when using `raise`https://bugs.ruby-lang.org/issues/94002014-01-12T05:03:53Zwardrop (Tom Wardrop)tom@tomwardrop.com
<p>When raising an error without defining an exception class, <code>::RuntimeError</code> appears to be a hard-coded default. I propose that this be changed so proper constant lookup rules are respected when looking up <code>RuntimeError</code>. For example, I would expect both of the <code>raise</code> calls in this example to be identical and use the redefined <code>RuntimeError</code> class with the <code>hello</code> method:</p>
<pre><code>module Test
class RuntimeError < RuntimeError
def hello
puts 'Hi there!'
end
end
begin
raise RuntimeError
rescue => e
e.hello #=> Hi there!
end
begin
raise
rescue => e
e.hello #=> undefined method `hello' for RuntimeError:RuntimeError
end
end
</code></pre>
<p>I would find this behavior to be of quite some convenience. A lot (most?) libraries only have a single error class, and this would allow developers to implicitly <code>raise</code> exceptions of the appropriate class.</p>
<p>Thoughts?</p> Ruby master - Feature #9355 (Open): Re: Rename method_id to method_name in TracePoint classhttps://bugs.ruby-lang.org/issues/93552014-01-03T19:27:09Zandhapp (Anuj Dutta)anuj@andhapp.com
<p>Hello,</p>
<p>I'd like to suggest renaming method_id (<a href="http://www.ruby-doc.org/core-2.1.0/TracePoint.html#method-i-method_id" class="external">http://www.ruby-doc.org/core-2.1.0/TracePoint.html#method-i-method_id</a>) to method_name in TracePoint class. There may be a particular reason for keeping it 'method_id', and I'd appreciate if someone could enlighten us.</p>
<p>Thanks.</p> Ruby master - Feature #9253 (Open): Regexp named match and case statementhttps://bugs.ruby-lang.org/issues/92532013-12-16T22:16:17Zoelmekki (Olivier El Mekki)olivier@el-mekki.com
<p>Hello,</p>
<p>I've notice there's no mean to use captured named matches with case<br>
statement :</p>
<pre><code>> a, b = "foo bar", nil
=> ["foo bar", nil]
> case a
> when /foo (?<b>bar)/ then p b
> end
nil
</code></pre>
<p>This is not critical, because we can use $1, $2 and friends in place, but it<br>
certainly would be nice and less surprising if it worked.</p>
<p>NB : btw, the link "How to report" [1] from tracker home page [2] is a 404.</p>
<p>[1] <a href="https://bugs.ruby-lang.org/projects/ruby/wiki/HowtoReport" class="external">https://bugs.ruby-lang.org/projects/ruby/wiki/HowtoReport</a><br>
[2] <a href="https://bugs.ruby-lang.org/" class="external">https://bugs.ruby-lang.org/</a></p> Ruby master - Bug #9189 (Assigned): Build failure on Windows in case of nonascii TEMP environment.https://bugs.ruby-lang.org/issues/91892013-12-01T18:06:20Zphasis68 (Heesob Park)phasis@gmail.com
<p>I experienced a build failure during build extension library with trunk on Windows.</p>
<pre><code>make[2]: Entering directory `/c/work/ruby-2.1.0-r43936/ext/bigdecimal'
generating bigdecimal-i386-mingw32.def
compiling bigdecimal.c
In file included from bigdecimal.c:20:0:
bigdecimal.h:62:1: error: static declaration of 'labs' follows non-static declar
ation
make[2]: *** [bigdecimal.o] Error 1
make[2]: Leaving directory `/c/work/ruby-2.1.0-r43936/ext/bigdecimal'
make[1]: *** [ext/bigdecimal/all] Error 2
make[1]: Leaving directory `/c/work/ruby-2.1.0-r43936'
make: *** [build-ext] Error 2
</code></pre>
<p>I found the cause of this error is mkmk failure.<br>
Here is a part of mkmf.log</p>
<pre><code>have_func: checking for labs() in stdlib.h... -------------------- no
"i686-w64-mingw32-gcc -o conftest.exe -I../../.ext/include/i386-mingw32 -I../.././include -I../.././ext/bigdecimal -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -L../.. -L. -lmsvcrt-ruby210-static -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi "
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Cannot create temporary file in C:\Users\??苑?AppData\Local\Temp\: Invalid argument
</code></pre>
<p>The TEMP environment varable is</p>
<pre><code>C:\work\ruby-2.1.0-r43936>set TEMP
TEMP=C:\Users\희섭\AppData\Local\Temp
</code></pre>
<p>It seems that miniruby cannot handle encoding properly.</p>
<pre><code>C:\work\ruby-2.1.0-r43936>miniruby -ve "p ENV['TEMP']"
ruby 2.1.0dev (2013-11-30 trunk 43936) [i386-mingw32]
"C:\\Users\\\xED\x9D\xAC\xEC\x84\xAD\\AppData\\Local\\Temp"
C:\work\ruby-2.1.0-r43936>miniruby.exe -ve "p ENV['TEMP'].encoding"
ruby 2.1.0dev (2013-11-30 trunk 43936) [i386-mingw32]
#<Encoding:ASCII-8BIT>
</code></pre>
<p>Whereas, the final ruby can handle encoding properly.</p>
<pre><code>C:\work>ruby -ve "p ENV['TEMP']"
ruby 2.1.0dev (2013-11-30 trunk 43923) [i386-mingw32]
"C:\\Users\\희섭\\AppData\\Local\\Temp"
C:\work>ruby -ve "p ENV['TEMP'].encoding"
ruby 2.1.0dev (2013-11-30 trunk 43923) [i386-mingw32]
#<Encoding:CP949>
</code></pre> Ruby master - Feature #9185 (Open): Add alias_class_method or class_alias functionalityhttps://bugs.ruby-lang.org/issues/91852013-12-01T03:39:32Zshevegen (Robert A. Heiler)shevegen@gmail.com
<p>Hi core team,</p>
<p>First drink a Calpis (カルピス Karupisu) before reading on :-)</p>
<p>Now, my proposal is to add a slight new feature that is mostly one of convenience.</p>
<p>We have two ways to use aliases:</p>
<p>(1) alias<br>
(2) alias_method</p>
<p>But are similar but not 100% the same.</p>
<p>Now this works all fine and nice.</p>
<p>But how to define a class method? Well, simple:</p>
<p>class Foo; def self.hi; puts 'hi'; end; end; Foo.hi</p>
<p>But how can we make an alias to this class method?</p>
<p>Well, this is ugly - here is one way:</p>
<p>class Foo; class << self; def ho; hi; end;end;end</p>
<p>Is this readable to you?</p>
<p>Using alias would be more readable.</p>
<p>Ok, we can simplify it by using alias:</p>
<p>class Foo; class << self; alias ho hi; end;end</p>
<p>But I don't like the class << self there, just to make<br>
a single class alias.</p>
<p>I thus propose a new method called:</p>
<p>class_alias</p>
<p>The above could then be rewritte like so perhaps:<br>
class Foo; class_alias :ho, :hi; end # I guess this would be more akin to alias_method</p>
<p>If the name is bad, it could be:</p>
<p>alias_class_method</p>
<p>Perhaps. Anyway, the name is not so important, I am sure a good name can be found,<br>
but I wonder if this would be a good feature to add or not.</p>
<p>Thanks for reading!</p> Ruby master - Feature #9174 (Open): value receiving block for Hash#has_key?https://bugs.ruby-lang.org/issues/91742013-11-29T06:33:11Zrits (First Last)
<p>Seems useful to be able to check for presence (as opposed to falsyness) and receive the value</p>
<p>class Hash<br>
def has_key?(key, &block)<br>
val = fetch(key){return false}<br>
block.(val) if block<br>
true<br>
end<br>
end</p>
<p>if h.has_key? :key do |val|</p>
<h1></h1>
<p>end; else</p>
<h1></h1>
<p>end</p> Ruby master - Feature #9145 (Open): Queue#pop(true) return nil if empty instead of raising Thread...https://bugs.ruby-lang.org/issues/91452013-11-24T12:42:25Zjsc (Justin Collins)
<p>I propose the non-blocking form of Queue#pop behave like Array#pop and return nil when empty.</p>
<p>Current behavior is to raise a ThreadError, with a message indicating the queue is empty.</p>
<p>For example:</p>
<p>q = Queue.new<br>
begin<br>
loop do<br>
next_item = q.pop(true)<br>
end<br>
rescue ThreadError</p>
<a name="queue-is-emptyor-maybe-something-bad-happened"></a>
<h1 >queue is empty...or maybe something bad happened<a href="#queue-is-emptyor-maybe-something-bad-happened" class="wiki-anchor">¶</a></h1>
<p>end</p>
<p>Instead, this could be</p>
<p>q = Queue.new<br>
while next_item = q.pop(true)<br>
end</p>
<p>Alternatively, raise an exception that is a subclass of ThreadError with a more specific name, such as "QueueEmpty". This would be a small improvement while remaining compatible with existing code.</p> Ruby master - Feature #9116 (Open): String#rsplit missinghttps://bugs.ruby-lang.org/issues/91162013-11-16T17:35:03Zartagnon (Ramkumar Ramachandra)artagnon@gmail.com
<p>There's nothing corresponding to Python's rsplit(). A quick glance at rb_str_split_m() tells me that it should be pretty trivial to implement. Is there any specific reason it hasn't already been done?</p> Ruby master - Feature #9111 (Open): Encoding-free String comparisonhttps://bugs.ruby-lang.org/issues/91112013-11-14T22:15:06Zsawa (Tsuyoshi Sawada)
<p>=begin<br>
Currently, strings with the same content but with different encodings count as different strings. This causes strange behaviour as below (noted in StackOverflow question <a href="http://stackoverflow.com/questions/19977788/strange-behavior-in-packed-ruby-strings#19978206" class="external">http://stackoverflow.com/questions/19977788/strange-behavior-in-packed-ruby-strings#19978206</a>):</p>
<pre><code>[128].pack("C") # => "\x80"
[128].pack("C") == "\x80" # => false
</code></pre>
<p>Since <code>[128].pack("C")</code> has the encoding ASCII-8BIT and <code>"\x80"</code> (by default) has the encoding UTF-8, the two strings are not equal.</p>
<p>Also, comparison of strings with different encodings may end up with a messy, unintended result.</p>
<p>I suggest that the comparison <code>String#<=></code> should not be based on the respective encoding of the strings, but all the strings should be internally converted to UTF-8 for the purpose of comparison.</p>
<p>=end</p> Ruby master - Feature #9095 (Open): Allow `Symbol#to_proc` to take argumentshttps://bugs.ruby-lang.org/issues/90952013-11-08T04:55:04Zalexeymuranov (Alexey Muranov)
<p>=begin<br>
After discussing <a class="issue tracker-2 status-7 priority-4 priority-default closed" title="Feature: New one-argument block syntax: &. (Feedback)" href="https://bugs.ruby-lang.org/issues/9076">#9076</a>, i've decided to propose this:</p>
<p>class Symbol<br>
def to_proc(*args)<br>
proc do |x|<br>
x.public_send(self, *args)<br>
end<br>
end<br>
end</p>
<p>p = :+.to_proc(1)</p>
<p>p[2] # => 3</p>
<p>[1, 2, 3, 4].map &:to_s.to_proc(2) #=> ["1", "10", "11", "100"]</p>
<p>This would allow constructing more kinds of procs without using literal blocks.<br>
=end</p> Ruby master - Feature #9049 (Open): Shorthands (a:b, *) for inclusive indexinghttps://bugs.ruby-lang.org/issues/90492013-10-24T11:54:48Zmohawkjohn (John Woods)john.o.woods@gmail.com
<p>For NMatrix, we've implemented a range shorthand which relies on Hashes: <code>m[1=>3, 2=>4]</code>, for example, which returns rows 1 through 3 inclusive of columns 2 through 4 (also inclusive). The original goal was to be able to do <code>m[1:3, 2:4]</code> using the new hash notation, but the new hash notation requires that the key be a symbol — it won't accept an integer.</p>
<p>Whether through the hash interface or not, it'd be lovely if there were a shorthand for slicing matrices (and even Ruby Arrays) using colon. This could just be an alternate syntax for ranges, also — which might make more sense.</p>
<p>The other related shorthand we'd love to find a way to implement is the all-inclusive shorthand. It gets to be a pain to type <code>n[0...n.shape[0], 1...3]</code> to get a submatrix (a slice), and it's really difficult to read. As a work-around, we currently use the <code>:*</code> symbol: <code>n[:*, 1...3]</code>. But it'd be simpler if there were a way to use a splat operator without an operand as a function argument. It might be a special case where the <code>*</code> is treated as a <code>:*</code> automatically. But this edge case might cause confusion with error messages when users make syntax errors elsewhere.</p>
<p>The colon shorthand is the highest priority for us.</p> Ruby master - Feature #8994 (Open): add methods for Float to get if an NaN is quiet or not, also ...https://bugs.ruby-lang.org/issues/89942013-10-08T16:45:30ZHanmac (Hans Mackowiak)hanmac@gmx.de
<p>Currently its not easy possible to know of an NaN in ruby is silent or not</p>
<p>like Float::NAN.quiet?</p>
<p>there should also methods to make an new NaN like Float::quiet_nan, maybe with the possibility to set user data</p>
<p>also there is</p>
<p>[Float::NAN].pack("g") #=> "\x7F\xC0\x00\x00"<br>
[0.0/0.0].pack("g") #=> "\xFF\xC0\x00\x00"</p>
<p>and</p>
<p>[-(0.0/0.0)].pack("g") #=> "\x7F\xC0\x00\x00"</p>
<p>so it seems that - can turn an quiet NaN into an loud one? (i am not 100% clear about that)<br>
specially when using two different NaN in one operation like</p>
<p>[(0.0/0.0) + Float::NAN].pack("g") #=> "\xFF\xC0\x00\x00"<br>
[Float::NAN + (0.0/0.0)].pack("g") #=> "\x7F\xC0\x00\x00"</p>
<p>Wikipedia says:<br>
For example, a bit-wise IEEE floating-point standard single precision (32-bit) NaN would be: s111 1111 1axx xxxx xxxx xxxx xxxx xxxx where s is the sign (most often ignored in applications), a determines the type of NaN, and x is an extra payload (most often ignored in applications). If a = 1, it is a quiet NaN; if a is zero and the payload is nonzero, then it is a signaling NaN.</p>
<p>so it seems that the negation does it a bit wrong? i mean -@ should not change the value like that?</p> Ruby master - Feature #8987 (Open): map/collect extension which handles argumentshttps://bugs.ruby-lang.org/issues/89872013-10-05T23:02:50Zsowieso (So Wieso)sowieso@dukun.de
<p>Please consider extending map/collect by allowing additional arguments to be passed to proc, like:<br>
A: <code>[1,2,3,4].map :+, 4</code><br>
and/or<br>
B: <code>[1,2,3,4].map 4, &:+</code></p>
<p>=> [5, 6, 7, 8]</p>
<p>Variant A is probably more readable. Variant B is more versatile (allows arbitrary arguments to be passed to block).</p> Ruby master - Feature #8970 (Open): Array.zip and Array.producthttps://bugs.ruby-lang.org/issues/89702013-10-01T03:57:09Zsawa (Tsuyoshi Sawada)
<p>=begin<br>
Most of the time when I use <code>Array#zip</code> or <code>Array#product</code>, I feel cumbursome that I have to take out the first array and pass it as a receiver. For example, if I have</p>
<pre><code>a = [[:a, :b, :c], [:d, :e, :f], [:g, :h, :i]]
</code></pre>
<p>I have to do something like this:</p>
<pre><code>a.first.zip(*a.drop(1)){...}
a.first.product(*a.drop(1)){...}
</code></pre>
<p>Sometimes, the receiver (i.e., the first array) has significance, but most other times, that breaks asymmetry, making the code look ugly.</p>
<p>I would be happy if we had <code>Array.zip</code> and <code>Array.product</code> in addition so that we can do it like this:</p>
<pre><code>Array.zip(*a){...}
Array.product(*a){...}
</code></pre>
<p>=end</p> Ruby master - Feature #8967 (Open): add uninclude and unextend methodhttps://bugs.ruby-lang.org/issues/89672013-09-30T14:18:34Zwindwiny (wind winy)windwinyubt@gmail.com
<p>Can be add uninclude and unextend method to ruby core ?</p>
<p>That enable Klass include or prepend different module,<br>
make DECORATOR design pattern is easier.</p> Ruby master - Feature #8961 (Open): Synchronizable module to easily wrap methods in a mutexhttps://bugs.ruby-lang.org/issues/89612013-09-27T20:23:16Ztobiassvn (Tobias Svensson)
<p>=begin<br>
I propose a Synchronizable mixin to easily wrap methods in a mutex which works together with Ruby 2.1's method name symbols returned from '(({def}))'.</p>
<p>The Mixin adds a new '(({synchronized}))' class method which would alias the referenced method and redefines the original method wrapped in a '(({synchronize do .. end}))' block.</p>
<p>This is probably somewhat related and an alternative to <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: MutexedDelegator as a trivial way to make an object thread-safe (Rejected)" href="https://bugs.ruby-lang.org/issues/8556">#8556</a>.</p>
<hr>
<p>Proof of concept (I've used Monitor here so potential users won't have to worry about reentrancy):</p>
<p>require 'monitor'</p>
<p>module Synchronizable<br>
module ClassMethods<br>
def synchronized(method)<br>
aliased = :"#{method}_without_synchronization"<br>
alias_method aliased, method</p>
<pre><code> define_method method do |*args, &block|
monitor.synchronize do
__send__(aliased, *args, &block)
end
end
end
end
def monitor
@monitor ||= Monitor.new
end
def self.included(base)
base.extend(ClassMethods)
end
</code></pre>
<p>end</p>
<p>class Foo<br>
include Synchronizable</p>
<pre><code>synchronized def bar
# ...
end
</code></pre>
<p>end<br>
=end</p> Ruby master - Feature #8947 (Open): make alias, alias_method, attr_* return name of the aliashttps://bugs.ruby-lang.org/issues/89472013-09-24T21:34:52Zrkh (Konstantin Haase)me@rkh.im
<p>Now that def returns the method name, it would be handy to have alias/alias_method return the name of the alias:</p>
<p>class Foo<br>
private def foo() end<br>
protected alias_method :bar, :foo<br>
end</p>
<p>Same goes for the attr_* methods:</p>
<p>class Foo<br>
private attr_accessor :foo, :bar<br>
end</p>
<p>What do you think?</p> Ruby master - Feature #8921 (Open): Allow select, reject, etc to accept a regexhttps://bugs.ruby-lang.org/issues/89212013-09-18T23:37:00Zkyledecot (Kyle Decot)kyle.decot@icloud.com
<p>It would be handy if <code>select</code> could accept a regex. For example</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="sx">%w[foo bar baz]</span><span class="p">.</span><span class="nf">select</span><span class="p">(</span><span class="sr">/^ba/</span><span class="p">)</span> <span class="c1"># => ["bar", "baz"] </span>
</code></pre>
<p>This is currently possible via the slightly longer syntax</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="sx">%w[foo bar baz]</span><span class="p">.</span><span class="nf">select</span><span class="p">{</span><span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="n">i</span><span class="p">[</span><span class="sr">/^ba/</span><span class="p">]}</span> <span class="c1"># => ["bar", "baz"] </span>
</code></pre> Ruby master - Feature #8896 (Open): #tap with missing blockhttps://bugs.ruby-lang.org/issues/88962013-09-11T19:05:44Zprijutme4ty (Ilya Vorontsov)prijutme4ty@gmail.com
<p>In case when no block provided to tap, it fails. So if you want method which can be called with or without block - you can't do it like this:</p>
<p>def self.create(args={}, &block)<br>
new.set_attributes(args).tap(&block)<br>
end</p>
<p>but should use block_defined? to prevent #tap's failure.</p>
<p>I suggest to make tap with no block given just to return self and raise no errors.</p> Ruby master - Feature #8862 (Open): getoptlong to accept user-provided commandlinehttps://bugs.ruby-lang.org/issues/88622013-09-04T21:53:13Znoon (Fabrice Bauzac)libnoon@gmail.com
<p>=begin<br>
Hello,</p>
<p>The (({getoptlong})) module (({class GetoptLong})) provides no way for the user to provide a commandline that is not (({ARGV})). It appears that (({GetoptLong})) is tied to the (({ARGV})) global variable and this cannot be modified. The fine (({getoptlong})) algorithms are not reusable in particular situations where the command is not in (({ARGV})), short of performing some kind of hack to temporarily modify (({ARGV})).</p>
<p>This ticket requests the addition of a way to redirect a (({GetoptLong})) object to eat a different (({Array})) of (({String})) than (({ARGV})).</p>
<p>One way to implement this would be to change the getoptlong code to use (({@argv})) instead of (({ARGV})), set (({@argv})) to a copy of (({ARGV})) in (({#initialize})), and provide a (({#set_commandline(Array)})) method to set (({@argv})) to a copy of the argument.<br>
=end</p> Ruby master - Feature #8853 (Open): Should String#sub(pattern) returns an Enumerator?https://bugs.ruby-lang.org/issues/88532013-09-03T10:08:08Zokkez (okkez _)
<p>調べてみたのですが、過去に同様の議論があったのかどうかわからなかったので起票します。</p>
<p>以下のように String#sub(pattern) と使うと ArgumentError が発生します。</p>
<p>$ ruby -e "p ''.sub(//)"<br>
-e:1:in <code>sub': wrong number of arguments (1 for 2) (ArgumentError) from -e:1:in </code>'</p>
<p>一方、 String#gsub(pattern) だと Enumerator を返します。</p>
<p>$ ruby -e "p ''.gsub(//)"<br>
#<Enumerator: "":gsub(//)></p>
<p>RDoc ではこの挙動は説明されていませんでした。<br>
String#gsub(pattern)がEnumeratorを返すことについては書かれています。<br>
<a href="http://www.ruby-doc.org/core-2.0.0/String.html#method-i-sub" class="external">http://www.ruby-doc.org/core-2.0.0/String.html#method-i-sub</a><br>
<a href="http://www.ruby-doc.org/core-2.0.0/String.html#method-i-gsub" class="external">http://www.ruby-doc.org/core-2.0.0/String.html#method-i-gsub</a></p>
<p>一貫性の観点から考えると、String#sub(pattern)もEnumeratorを返した方が良いように思いましたがいかがでしょうか。<br>
まあ、String#sub だと置換は一回しか発生しないのでイマイチな感じはします。</p>
<ul>
<li>String#sub(pattern) が Enumerator を返すようになる</li>
<li>RDoc に String#gsub(pattern) と違って String#sub(pattern) が ArgumentError を発生させることの記述が追加される</li>
</ul>
<p>のどちらかが、満たされればいいと思っています。</p> Ruby master - Feature #8848 (Open): Syntax for binary stringshttps://bugs.ruby-lang.org/issues/88482013-08-31T15:59:43Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<p>In commit 37486, Yui (Naruse) added a String#b method as proposed in <a href="http://bugs.ruby-lang.org/issues/6767" class="external">http://bugs.ruby-lang.org/issues/6767</a>.</p>
<p>String#b was added to allow easy generation of binary strings; this became necessary in particular after the source file encoding was changed to UTF-8.</p>
<p>However, as also recognized in <a href="http://bugs.ruby-lang.org/issues/6767" class="external">http://bugs.ruby-lang.org/issues/6767</a>, in the long term (ideally starting with Ruby 2.1) it would be better to make binary strings available as part of Ruby syntax.</p>
<p>One reason for this efficiency. String#b creates a duplicate object, which is not at all necessary for the frequent use case of String literals.</p>
<p>Another reason is encoding validity. To be able to e.g. create a "\xFF" binary string, with String#b in an UTF-8 source context, it is necessary to allow "\xFF" (temporarily at least) as an (actually invalid) UTF-8 string. This may be difficult for some implementations, and isn't desirable in general.</p>
<p>Regarding syntax, there are mainly two solutions:</p>
<ol>
<li>a '%b' prefix</li>
<li>a 'b' suffix</li>
</ol>
<p>The preferable syntax depends on the overall future approach of Ruby to String literal suffixes (see <a href="https://bugs.ruby-lang.org/issues/8579" class="external">https://bugs.ruby-lang.org/issues/8579</a>).</p> Ruby master - Feature #8834 (Open): Kernel#load_relativehttps://bugs.ruby-lang.org/issues/88342013-08-30T10:32:44Zsawa (Tsuyoshi Sawada)
<p>The intended difference between <code>Kernel#require</code> and <code>Kernel#load</code> is that the former is for external libraries and the latter is for Ruby scripts internal to the project. Considering this fact, <code>load</code> should be more likely than <code>require</code> to be used in a situation where you want to call a file through a relative path. Strangely, there is <code>Kernel#require_relative</code>, but no <code>Kernel#load_relative</code>. I request <code>Kernel#load_relative</code>. It is even more necessary than <code>Kernel#require_relative</code>.</p>
<p>It seems to me that people are using <code>Kernel#require_relative</code> when they want to use a relative path, even in the context where they are supposed to use <code>load</code> because of the lack of <code>Kernel#load_relative</code>. I don't think this is a good practice. Furthermore, in cases where you have a file without a <code>.rb</code> or other extention that you want to call via a relative path, there is no good way to do it.</p> Ruby master - Feature #8807 (Open): Custom literalshttps://bugs.ruby-lang.org/issues/88072013-08-21T18:20:52Ztrans (Thomas Sawyer)
<p>So why can't we define custom literals? There's been recent discussion about adding a new freeze literal. Would have been nice if coders could have defined it for themselves, then it would have been more clear if there really was enough use to add it to core.</p>
<p>I imagine the syntax of such a feature to be quite simple.</p>
<p>def %foo(string, mod=nil)<br>
p [string, mod]<br>
end</p>
<p>%foo{something}o<br>
=> ["something", "o"]</p> Ruby master - Feature #8786 (Open): Process.clock_gettime(:realtime)https://bugs.ruby-lang.org/issues/87862013-08-15T22:33:13Zznz (Kazuhiro NISHIYAMA)
<p>Socket や IO#seek のように Process.clock_gettime の第一引数も Symbol で :realtime などを受け付けると良いのではないでしょうか。</p> Ruby master - Feature #8772 (Open): Hash alias #| merge, and the case for Hash and Array polymorp...https://bugs.ruby-lang.org/issues/87722013-08-11T11:46:03Ztrans (Thomas Sawyer)
<p>Ideally Hash and Array would be completely polymorphic in every manner in which it is possible for them to be so. The reason for this is very simple. It makes a programmer's life easier. For example, in a recent program I was working on, I had a list of keyboard layouts.</p>
<p>layouts = [layout1, layout2, layout3]</p>
<p>Later I realized I wanted to identify them by a label not an index. So...</p>
<p>layouts = {:foo => layout1, :bar => layout2, :baz => layout3}</p>
<p>Unfortunately this broke my program in a number of places, and I had to go through every use of <code>layouts</code> to translate what was an Array call into a Hash call. If Array and and Hash were more polymorphic I would have only had to adjust the places were I wanted to take advantage of the Hash. Ideally almost nothing should have actually broken.</p>
<p>The achieve optimal polymorphism between Hash and Array is to treat a Hash's keys as indexes and its values as as the values of an array. e.g.</p>
<p>a = [:a,:b,:c]<br>
h = {0=>:a,1=>:b,2=>:c}<br>
a.to_a #=> [:a,:b,:c]<br>
h.to_a #=> [:a,:b,:c]</p>
<p>Of course the ship has already sailed for some methods that are not polymorphic, in particular #each. Nonetheless it would still be wise to try to maximize the polymorphism going forward. (Perhaps even to be willing to take a bold leap in Ruby 3.0 to break some backward compatibility to improve upon this.)</p>
<p>In the mean time, let us consider what it might mean for Hash#+ as an alias for #merge, <em>if the above were so</em>:</p>
<p>([:a,:b] + [:c,:d]).to_a => [:a,:b,:c,:d]<br>
({0=>:a,1=>:b} + {2=>:c,3=>:d}).to_a => [:a,:b,:c,:d]</p>
<p>([:a,:b] + [:a,:b]).to_a => [:a,:b,:a,:b]<br>
({0=>:a,1=>:b} + {0=>:a,1=>:b}).to_a => [:a,:b]</p>
<p>Damn! So it appears that #+ isn't the right operator. Let's try #| instead.</p>
<p>([:a,:b] | [:c,:d]).to_a => [:a,:b,:c,:d]<br>
({0=>:a,1=>:b} | {2=>:c,3=>:d}).to_a => [:a,:b,:c,:d]</p>
<p>([:a,:b] | [:a,:b]).to_a => [:a,:b]<br>
({0=>:a,1=>:b} | {0=>:a,1=>:b}).to_a => [:a,:b]</p>
<p>Bingo. So I formally stand corrected. The best alias for merge is #| not #+.</p>
<p>Based on this line of reasoning I formally request the Hash#| be an alias of Hash#merge.</p>
<p>P.S. Albeit, given the current state of polymorphism between Ruby's Array and Hash, and the fact that it will probably never be improved upon, I doubt it really matters which operator is actually used.</p> Ruby master - Feature #8751 (Open): Add offsets to method#source_locationhttps://bugs.ruby-lang.org/issues/87512013-08-08T14:03:29Ztenderlovemaking (Aaron Patterson)tenderlove@ruby-lang.org
<p>Hello,</p>
<p>I would like to have byte offsets returned on the source_location for methods. For example:</p>
<p>def foo(&b)<br>
b.source_location # => [file_name, line_number, start_byte, end_byte]<br>
end</p>
<p>If we had the start and end byte for a method or proc, then we could find the source for methods and procs in each file. There are some cases (like with heredocuments) where the "end of the method" could be after the <code>end</code> keyword. But I think if we just have offsets for the start of <code>def</code> and the end of <code>end</code>, I think it would cover 99% of usecases.</p> Ruby master - Feature #8714 (Open): Non-interpolated regular expression literalhttps://bugs.ruby-lang.org/issues/87142013-08-01T08:07:19Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<p>=begin</p>
<p>I propose a new %string for non-interpolated regexp literals: %R</p>
<p>It is common to see erroneous bug reports around the use of ((%#%)) in regexp literals, for example where (({/[$#]/})) raises a syntax error "unexpected $undefined", and this confuses people. The only solution is to rearrange the regular expression (such as (({/[$#]/}))), which is not always desirable.</p>
<p>An non-interpolated regexp, such as (({%R/[$#]/})), would allow a much simpler resolution.</p>
<p>=== Known Issues</p>
<ul>
<li>the capitalisation is the opposite of %Q(interpolated) and %q(uninterpolated)</li>
<li>%R was also proposed for literal Rationals in <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Rational number literal (Closed)" href="https://bugs.ruby-lang.org/issues/8430">#8430</a>, although I believe this has been superseded by the (({1.2r})) syntax</li>
</ul>
<p>=end</p> Ruby master - Feature #8688 (Open): #sprintf should accept strings as keyshttps://bugs.ruby-lang.org/issues/86882013-07-26T02:33:03ZQuintus (Marvin Gülker)post+rubybugs@guelker.eu
<p>=begin<br>
Hi there,</p>
<p>Kernel#sprintf should support strings as keys. Currently it only works with symbols:</p>
<p>{irb(main):001:0> str = "This is %{foo}."<br>
=> "This is %{foo}."<br>
irb(main):002:0> sprintf(str, :foo => "bar")<br>
=> "This is bar."<br>
irb(main):003:0> sprintf(str, "foo" => "bar")<br>
KeyError: key{foo} not found<br>
from (irb):3:in <code>sprintf' from (irb):3 from /opt/rubies/mri/bin/irb:12:in </code>'}</p>
<p>ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]</p>
<p>If I want a user to be able to enter format strings and (later) the corresponding parameter values, I don’t want to call #to_sym on the keys (because generating symbols from user input is known to cause memory issues).</p>
<p>Valete,<br>
Marvin</p>
<p>=end</p> Ruby master - Feature #8681 (Open): Net::HTTP should set TCP_NODELAY for requests with bodyhttps://bugs.ruby-lang.org/issues/86812013-07-25T03:40:34Znormalperson (Eric Wong)normalperson@yhbt.net
<p>Setting TCP_NODELAY to disable Nagle's algorithm speeds up successive writes which<br>
we use when sending HTTP PUT/POST requests with body.</p>
<p>From <a href="https://en.wikipedia.org/wiki/Nagle%27s_algorithm" class="external">https://en.wikipedia.org/wiki/Nagle%27s_algorithm</a></p>
<pre><code> The user-level solution is to avoid write-write-read sequences on
sockets. write-read-write-read is fine. write-write-write is
fine. But write-write-read is a killer. So, if you can, buffer up
your little writes to TCP and send them all at once. Using the
standard UNIX I/O package and flushing write before each read
usually works.
</code></pre>
<p>We currently hit the killer write-write-read case when sending requests<br>
with body using Net::HTTP</p>
<p>net-http-persistent does this by default (for all connections), even.<br>
I usually use net-http-persistent, but sometimes it's easier to use<br>
Net::HTTP on a new (bare) system and I've been bitten by this :x</p> Ruby master - Feature #8640 (Open): Add Time#elapsed to return nanoseconds since creationhttps://bugs.ruby-lang.org/issues/86402013-07-16T03:39:06Ztenderlovemaking (Aaron Patterson)tenderlove@ruby-lang.org
<p>Hi,</p>
<p>We time many things in Rails (and so does lots of other code), and I've found that we spend lots of time allocating and subtracting time objects. For example:</p>
<p>start = Time.now</p>
<a name="do-stuff-we-want-to-time"></a>
<h2 >do stuff we want to time<a href="#do-stuff-we-want-to-time" class="wiki-anchor">¶</a></h2>
<p>finish = Time.now - start</p>
<p>It would be nice if we could just create one time object and grab the nanoseconds elapsed since the time object was created like so:</p>
<p>start = Time.now</p>
<a name="do-stuff-we-want-to-time-2"></a>
<h2 >do stuff we want to time<a href="#do-stuff-we-want-to-time-2" class="wiki-anchor">¶</a></h2>
<p>finished = start.elapsed # => nanoseconds elapsed.</p>
<p>I've attached a patch that implements this feature.</p> Ruby master - Feature #8635 (Open): attr_accessor with default blockhttps://bugs.ruby-lang.org/issues/86352013-07-14T23:59:56Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>=begin</p>
<p>It's quite common to define attributes (like attr_reader, attr_accessor) with default values. It would be useful if Ruby provided a helper method for this case. attr_accessor and attr_reader can support this nicely using a default block:</p>
<p>class Person</p>
<a name="1-Simple-approach"></a>
<h1 >(1) Simple approach<a href="#1-Simple-approach" class="wiki-anchor">¶</a></h1>
<p>attr_writer :name<br>
def name<br>
@name ||= 'Hello'<br>
end</p>
<a name="2-nil-safe-approach"></a>
<h1 >(2) nil-safe approach<a href="#2-nil-safe-approach" class="wiki-anchor">¶</a></h1>
<p>attr_writer :name<br>
def name<br>
return @name if defined? @name<br>
@name = 'Hello'<br>
end</p>
<a name="3-This-proposal"></a>
<h1 >(3) This proposal<a href="#3-This-proposal" class="wiki-anchor">¶</a></h1>
<p>attr_accessor :name do<br>
'Hello'<br>
end<br>
end</p>
<p>p = Person.new<br>
p.instance_variable_get(:@name) # => nil<br>
p.name # => 'Hello'<br>
p.instance_variable_get(:@name) # => 'Hello'</p>
<p>Problems with current approaches:</p>
<ul>
<li>The reader and the writer looks widely different</li>
<li>Solution 1 doesn't work as intended when the default value may evaulate to nil/false</li>
<li>Solution 2 requires you to write the attribute name five times</li>
</ul>
<p>=end</p> Ruby master - Feature #8626 (Open): Add a Set coercion method to the standard lib: Set(possible_set)https://bugs.ruby-lang.org/issues/86262013-07-12T01:26:27Zsaturnflyer (Jim Gay)
<p>=begin<br>
I'd like to be able to take an object that may already be a Set (or not) and ensure that it is one</p>
<p>For example:</p>
<pre><code>set1 = Set.new
set2 = Set(set1)
set3 = Set(nil)
assert set1.equal?(set2)
assert_instance_of(Set, set3)
</code></pre>
<p>This is different from the behavior of Set.new in that it will return the same set rather than creating a new one</p>
<pre><code>set1 = Set.new
set2 = Set.new(set1) # <--- completely new object in memory
set2 = Set(set1) # <--- same object from memory
</code></pre>
<p>My thoughts about the implementation are simple:</p>
<pre><code>def Set(possible_set)
possible_set.is_a?(Set) ? possible_set : Set.new(possible_set)
end
</code></pre>
<p>I'm not sure if there are edge cases to unexpected behavior that I haven't thought of and I'm wondering if it ought to have a Set.try_convert as well<br>
=end</p> Ruby master - Feature #8619 (Open): Standard Profiling APIhttps://bugs.ruby-lang.org/issues/86192013-07-10T19:51:29Zyorickpeterse (Yorick Peterse)yorickpeterse@gmail.com
<p>At the time of writing there are many different Ruby implementations ranging<br>
from the common ones such as MRI, Jruby and Rubinius to slightly less common<br>
ones such as mruby and Topaz.</p>
<p>A recurring problem in all these implementations is that there's no standard<br>
API for profiling resource usage. For example, for MRI there's ruby-prof but in<br>
order to get garbage collection and memory usage related information you have<br>
to patch MRI. As far as I'm aware of Jruby is the only implementation that at<br>
this point offers proper tools for profiling your Ruby application as it piggy<br>
backs on top of the JVM and all the awesome profiling tools that come with it.</p>
<p>What I'd hereby like to propose is an API for all Ruby implementations that<br>
allows developers to profile at least the following:</p>
<ul>
<li>Garbage collection information</li>
<li>Memory usage</li>
<li>Object allocations</li>
</ul>
<p>These items are discussed in detail below.</p>
<a name="Topics"></a>
<h2 >Topics<a href="#Topics" class="wiki-anchor">¶</a></h2>
<a name="Garbage-Collection"></a>
<h3 >Garbage Collection<a href="#Garbage-Collection" class="wiki-anchor">¶</a></h3>
<p>In the past one would have to use REE or install a bunch of patches in order to<br>
get GC information such as when it would run, how many objects it processed,<br>
etc. What I'd like to see here is the following:</p>
<ul>
<li>When the GC starts/stops</li>
<li>How many objects are freed and how many are left intact</li>
<li>The time it takes for the GC to run</li>
</ul>
<p>If applicable there could be more added, this is just what I can think of from<br>
the top of my head.</p>
<a name="Memory-Usage"></a>
<h3 >Memory Usage<a href="#Memory-Usage" class="wiki-anchor">¶</a></h3>
<p>Next to the GC this is a particular important addition. Similar to GC<br>
information one would have to install MRI patches to get memory usage<br>
information or worse, use something along the lines of the following:</p>
<pre><code># Returns memory usage of the entire process in KB
def memory_usage
return `ps -o rss= #{Process.pid}`.strip.to_f
end
</code></pre>
<p>The above code is actually fairly common but also inaccurate and adds a pretty<br>
big overhead as a subshell has to be started for every call. It also wouldn't<br>
work on systems where <code>ps</code> is not available or would otherwise work<br>
differently.</p>
<p>Ideally one should be able to get the memory usage of individual memory calls<br>
similar to what you can now achieve using ruby-prof + a set of patches. This<br>
would greatly reduce the amount of time and effort required to hunt down memory<br>
leaks or otherwise memory intensive operations when it's not entirely clear why<br>
something is not performing as well as it should.</p>
<a name="Object-Allocations"></a>
<h3 >Object Allocations<a href="#Object-Allocations" class="wiki-anchor">¶</a></h3>
<p>This one goes a bit hand in hand with the memory usage topic. Ideally one<br>
should be able to get the amount of allocated objects per method call in a bit<br>
more accurage way than ObjectSpace currently provides. For example, it would be<br>
nice if one could see that method X allocated 2500 String objects, 2 Array<br>
Objects and 1 Foo::Bar object.</p>
<a name="API-Design"></a>
<h2 >API Design<a href="#API-Design" class="wiki-anchor">¶</a></h2>
<p>Code wise I'm not entirely sure how this would look, which is part of why I'm<br>
opening this feature request. I'm thinking out loud here but I was thinking of<br>
something along the lines of the following:</p>
<pre><code>require 'profiler/memory'
require 'profiler/allocations'
require 'profiler/gc'
# The same would be used for memory and allocation profiling but using
# different constants (e.g. MemoryProfiler and AllocationProfiler)
GC.enable_profiling
# Do some serious Ruby work here
# Here `result` would contain the profiling results per method call made
# since profiling was enabled.
result = GC.disable_profiling
</code></pre>
<p>The core idea however is that every Ruby implementation would offer the same<br>
public API (though the internals may differ). This way one could write a tool<br>
that for example displays a graph of the memory usage over time that would work<br>
in all the Ruby implementations. Currently this is not something that's<br>
possible due to the vastly different APIs (or total lack thereof).</p>
<p>Note that this request isn't a "I want this and I want it now" request but more<br>
the start of a discussion about such an API. The amount of time and effort<br>
required to get this to work on the various implementations could easily take<br>
months if not a few years (heavily depending on the amount of people<br>
available). Especially if you consider that some implementations might<br>
currently not even make the required information publically available.</p>
<p>So to cut a long story short: I hereby open the discussion on a common API for<br>
profiling resource usage in the varios Ruby implementations.</p>
<p>p.s. Although I'd also be interested in seeing execution time of methods and<br>
such I'm not entirely sure how I'd envision such an API. As such I've left it<br>
out of this request but of course everybody is welcome to discuss/include that<br>
as well.</p> Ruby master - Feature #8614 (Open): Object#singleton_class with a blockhttps://bugs.ruby-lang.org/issues/86142013-07-10T01:04:42Zsawa (Tsuyoshi Sawada)
<p>=begin<br>
Most of the time when I use <code>Object#singleton_class</code>, I use it with <code>class_eval</code> following it, like follows:</p>
<pre><code>class Foo
singleton_class.class_eval{attr_accessor :bar}
end
</code></pre>
<p>I think it would be convenient if <code>Object#singleton_class</code> can optionally take a block so that the following will mean the same as above.</p>
<pre><code>class Foo
singleton_class{attr_accessor :bar}
end
</code></pre>
<p>=end</p> Ruby master - Feature #8598 (Open): Expose information whether a timezone offset has been explici...https://bugs.ruby-lang.org/issues/85982013-07-03T20:27:06Zgpoul (Gerhard Poul)gerhard.poul@gmail.com
<p>For some applications it would be beneficial if Ruby would expose information on whether a DateTime object has an explicitly set timezone offset. An application might want to use DateTimes that don't concern themselves with timezone offsets and don't perform conversions between zones. To make this backwards compatible I'd suggest to expose a flag on whether an offset has been set or whether the default (offset=0) has been automatically assumed. An application might then decide to handle a DateTime that has the default timezone offset automatically assumed (offset=0) differently from a DateTime that has UTC (offset=0) set explicitly.</p> Ruby master - Feature #8570 (Open): Better mechanisms to safely load classes concurrentlyhttps://bugs.ruby-lang.org/issues/85702013-06-26T06:48:01Zheadius (Charles Nutter)headius@headius.com
<p>Today I had an issue reported under JRuby where a user was doing require "some library" unless defined?(SomeClassLibraryDefines). They were running into cases where threads hitting this logic concurrently might see a partially-initialized.</p>
<p>This pattern is not uncommon, and it is broken under <em>all</em> Ruby implementations. I believe this is a major flaw in the way Ruby makes classes visible, and we need to think about changes to how constants are defined during class init or come up with better options for concurrent loading. This bug offers a few ideas and experiments I've tried in hopes we can find something that will work.</p>
<p>The most basic problem is that the constant pointing at the class is set immediately upon opening the class. So the first option is:</p>
<ol>
<li>Do not define the constant until leaving the class/module body.</li>
</ol>
<p>This option would prevent concurrent threads from seeing an uninitialized class. In essence, this code:</p>
<p>class Foo<br>
def method1 ...<br>
def method2 ...<br>
end</p>
<p>would operated identically to this code:</p>
<p>Foo = Class.new do<br>
def method1 ...<br>
def method2 ...<br>
end</p>
<p>A defined? check on Foo would return false until the class was completely initialized, and lazily require + defined would work correctly.</p>
<p>However, there are pieces of code out there that depend on being able to access the constant from within the class/module body. This brings me to a second option I experimented with on JRuby:</p>
<ol start="2">
<li>Make the constant visible only to the defining thread until leaving the class/module body.</li>
</ol>
<p>In JRuby, I accomplished this by using Clojure's STM to implement the constant table. The beginning of opening a new class would start an STM transaction. The new, empty class body would be written into the constant table as part of the transaction, only visible to the current thread. Once the class body closed, the transaction would be committed and all code would see a complete class at that constant.</p>
<p>This version solves most issues with #1. The constant is available to that thread, so if code loading or class definition depends on the constant being available, it will still work. It prevents other threads from seeing a partially-initialized class. And it does not interrupt the normal flow of the program.</p>
<p>There are down sides, though, that may or may not happen in practice. If two threads try to start defining a class and it has never been defined before, only one will win. If code loading or class definition logic within the class/module spin up other threads, they won't be able to see the constant.</p>
<p>So then, perhaps we simply need a better mechanism to know if a given class is "complete" or not?</p>
<ol start="3">
<li>Add an attribute to Module indicating whether the class is "open" somewhere in the system.</li>
</ol>
<p>This would change the require check above to look more like this:</p>
<p>require 'some library' if !defined?(SomeLibrary) || SomeLibrary.open?</p>
<p>The logic here says "if SomeLibrary is not defined or is still being defined, attempt to do the require, which should block until done loading".</p>
<p>But this is somewhat ugly, so I have a fourth suggestion:</p>
<ol start="4">
<li>Add a new mechanism for concurrent requires that understands the services those requires provide.</li>
</ol>
<p>This would be something like:</p>
<p>require_service(:some_service_name, "some library")</p>
<p>This would behind the scenes perform checks for whether some_service_name was completely loaded as a service, and only define mark that service as "loaded" once the require had <em>completed</em>. This fixes all issues with all scenarios above. However, this basically ends up being:</p>
<p>require "some library" unless $".include?("some library")</p>
<p>...but with a user-provided name rather than the filename going into the equivalent of LOADED_FEATURES.</p>
<p>So...these are some brainstorming ideas. What do you think, Ruby world?</p> Ruby master - Feature #8566 (Open): [PATCH] Allow to configure additional preludeshttps://bugs.ruby-lang.org/issues/85662013-06-24T20:37:18Zvo.x (Vit Ondruch)v.ondruch@tiscali.cz
<p>Could you please accept the patch [1], which adds new '--with-prelude' configuration option. This configuration option allows to specify additional preludes and compile it into prelude.c, therefore execute the code on each start of Ruby.</p>
<p>= Rationale</p>
<p>In Fedora/RHEL/CentOS, there is ABRT tool [2], which allows to automatically report program failures. I developed abrt gem [3, 4], which adds support for catching of unhandled Ruby exceptions, this in turns help improve the quality of Fedora and software we ship.</p>
<p>Every Ruby programmer could require this gem and it would report the bugs, however, there is no way how to convince everybody, that they should use abrt gem. Therefore, it would make more sense, if the gem is automatically loaded by Ruby itself, when it is available on system. For that, I could patch Ruby, but I think somebody else could benefit from this feature as well, hence I am proposing this patch to upstream.</p>
<p>JFYI, Motohiro Kosaki once proposed to add ABRT support to Ruby [5], but I think it would be far better if Ruby knows nothing about ABRT by default and we could solve it on distribution level.</p>
<p>Thanks for considering.</p>
<p>[1] <a href="https://github.com/voxik/ruby/commit/efcca5238cf0804275e76d99a599190250d9dd0c" class="external">https://github.com/voxik/ruby/commit/efcca5238cf0804275e76d99a599190250d9dd0c</a><br>
[2] <a href="https://fedorahosted.org/abrt/" class="external">https://fedorahosted.org/abrt/</a><br>
[3] <a href="http://rubygems.org/gems/abrt" class="external">http://rubygems.org/gems/abrt</a><br>
[4] <a href="https://github.com/voxik/abrt-ruby" class="external">https://github.com/voxik/abrt-ruby</a><br>
[5] <a href="https://github.com/kosaki/ruby/commit/6283017dc2747f306808ce530292dc51273746ec" class="external">https://github.com/kosaki/ruby/commit/6283017dc2747f306808ce530292dc51273746ec</a></p> Ruby master - Feature #8564 (Open): Extend Module#attr... methodshttps://bugs.ruby-lang.org/issues/85642013-06-24T13:55:07ZAnonymous
<p>Extend #attr_reader, #attr_writer, #attr_accessor syntax to accept default values, such as:</p>
<pre><code>attr_reader foo: 42, bar: 43
</code></pre>
<p>Possibility of closures evaluated at initialization time might also be considered:</p>
<pre><code>attr_reader baz: -> { Time.now }, quux: 42
</code></pre> Ruby master - Feature #8544 (Open): OpenURI should open 'file://' URIshttps://bugs.ruby-lang.org/issues/85442013-06-19T23:35:21Zsilasdavis (Silas Davis)ruby-lang@silasdavis.net
<p>The following code prints the contents of '/tmp/file.txt':</p>
<p>require 'open-uri'<br>
open('/tmp/file.txt').read {|f| puts f.read }</p>
<p>which although useful should probably fail since a unix file path is not a URI, and therefore might shield data problems in a system</p>
<p>However the following should produce the same output and is a URI, but fails:</p>
<p>open('file:///tmp/file.txt').read {|f| puts f.read }</p>
<p>I note that the documentation for open-uri does explain that it is a wrapper for http, https, and ftp, but to deserve its name it should open such URIs as specified in this RFC: <a href="http://tools.ietf.org/html/rfc1630" class="external">http://tools.ietf.org/html/rfc1630</a>. This coupled with the fact that it already does open files, but not by a URI specification.</p> Ruby master - Feature #8494 (Open): Safe method for defensive copies. alternative to 'dup'https://bugs.ruby-lang.org/issues/84942013-06-05T16:26:27Zellipsoid (Andrew Northrop)andrew.northrop@gmail.com
<p>As a developer<br>
I want a simple method that will return a "safe" version of my object<br>
So I can make defensive copies easily and safely</p>
<p>This is related to issue 1844: <a href="http://www.ruby-forum.com/topic/3650325" class="external">http://www.ruby-forum.com/topic/3650325</a></p>
<p>I have tried using 'dup' to make defensive copies, but 'dup' throws an exception when used on a Fixnum and the like, because these values aren't copyable.</p>
<p>I tried to throw a "respond_to?" around the call, but that didn't work, since these classes still technically respond to 'dup'.</p>
<p>It looks like there's an extension method to do this (<a href="http://ruby-doc.org/gems/docs/c/core_ex-0.6.6.3/CoreEx/TryDup.html" class="external">http://ruby-doc.org/gems/docs/c/core_ex-0.6.6.3/CoreEx/TryDup.html</a>), but I don't see why this isn't in the core language. It seems like a common enough use case.</p>
<p>As far as naming, 'dup' is really just the means to an end. A more meaningful name would be something like 'defensive', or 'safe'. Although 'try_dup' like the extension method would also work.</p>
<p>Any chance of something like this making it in to Ruby core?</p> Ruby master - Feature #8452 (Open): Kernel#otherwise to rewrite code like (obj || default_obj).do...https://bugs.ruby-lang.org/issues/84522013-05-26T20:41:57Zprijutme4ty (Ilya Vorontsov)prijutme4ty@gmail.com
<p>Imagine you have code like this<br>
(long_computation_chain || []).do_smth<br>
While it isn't difficult, but it forces a developer to use additional parentheses. It can be difficult to trace where opening bracket is when computation_chain is long. Due to this idiom code cannot be read or written left to right. This is the same problem as for<br>
Hash[ *long_computation ]</p>
<p>So I propose a simple method Kernel#otherwise</p>
<pre><code>def otherwise(value, check = nil)
if !check
self || value
else
check.to_proc.call(self) ? self : value
end
end
</code></pre>
<p>So now one can write:<br>
long_computation_chain.otherwise([]).do_smth<br>
or<br>
long_computation_chain.otherwise('default', :empty?).do_smth<br>
or<br>
long_computation_chain.otherwise('numbers not allowed', ->(x){ x.grep(/\d+/) }).do_smth</p> Ruby master - Feature #8437 (Open): custom operators, unicodehttps://bugs.ruby-lang.org/issues/84372013-05-23T09:20:16Zeike.rb (Eike Dierks)eike@inter.net
<p>The ruby language does currently one support a predefined set of operators.<br>
It would be nice to add custom operators.<br>
A lot of people ask about the elvis operator aka (?:) to cope with nil, aka rails try()</p>
<p>This probably is a problem with the parser at first,<br>
because introducing new operators makes parsing a lot more complicated.</p>
<p>Maybe we could allow symbols from the unicode space<br>
to be used as new operators?<br>
That would be compatible with all before code written in ascii.</p>
<p>So we could allow all the symbols from the unicode Math operators plane<br>
to be available as operators in Ruby.</p>
<p>While few of you might have tried that,<br>
Unicode is fully available for naming identifiers.</p>
<p>We should also extend the set of operators to the unicode space.</p>
<p>While we are still not used to it now,<br>
to have some unicode characters in our codes,<br>
could really add to the expressivness.</p>
<p>So as of today, you can already name your variable like<br>
delta_t or Δt</p>
<p>Or if you're working with angles,<br>
you might call your variables α or Θ<br>
This is completely legal in Ruby.</p>
<p>I'm asking for:<br>
this_set ∪ other_set</p>
<p>or maybe we could even do this for prefix like:<br>
√2</p>
<p>I'd believe the math operator plane of unicode should be removed<br>
from the allowable names of identifiers,<br>
but should instead be reserved for operators in the parser, like + nowdays is.</p> Ruby master - Feature #8404 (Open): virtual, hooked or read only global variabels for ruby only c...https://bugs.ruby-lang.org/issues/84042013-05-14T21:19:29ZHanmac (Hans Mackowiak)hanmac@gmx.de
<p>currently pure virtual or hooked global variables can only be defined with cFunctions like rb_define_virtual_variable</p>
<p>i think it would be cool if this would be possible in Ruby code too</p> Ruby master - Feature #8366 (Open): Exception.message take time to execute depending on the insta...https://bugs.ruby-lang.org/issues/83662013-05-04T08:11:37Zanuraguniyal (anurag uniyal)anuraguniyal@gmail.com
<p>I am seeing very interesting and catastrophic behavior with ruby, see the code below</p>
<pre><code>class ExceptionTest
def test
@result = [0]*500000
begin
no_such_method
rescue Exception => ex
puts "before #{ex.class}"
st = Time.now
ex.message
puts "after #{Time.now-st} #{ex.message}"
end
end
end
ExceptionTest.new.test
</code></pre>
<p>Ideally ex.message should not take any time to execute and hence Time taken should be in ms, but here is the output</p>
<pre><code>ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.4.2]
before NameError
after 0.462443 undefined local variable or method `no_such_method' for #<ExceptionTest:0x007fc74a84e4f0>
</code></pre>
<p>If I assign <code>[0]*500000</code> to a local variable instead of instance variable e.g. <code>result = [0]*500000</code> it runs as expected</p>
<pre><code>ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.4.2]
before NameError
after 2.8e-05 undefined local variable or method `no_such_method' for #<ExceptionTest:0x007ff59204e518>
</code></pre>
<p><strong>It looks like somehow <code>ex.message</code> is looping thru the instance variables, why it would do so, please enlighten me!</strong></p>
<p>I have tried it on ruby ruby-1.9.2-p290, ruby-1.9.1-p376 and whatever version the ruby on codepad.org is.</p> Ruby master - Feature #8321 (Open): Ripper: I would like coordinates for keywordshttps://bugs.ruby-lang.org/issues/83212013-04-25T08:10:04Zericp (Eric Promislow)eric.promislow@gmail.com
<p>=begin<br>
Ripper gives the (({[line, column]})) coordinates for identifiers, strings, and numbers.</p>
<p>I would like it if it appended those coordinates to most of the block keywords,<br>
including (({:program})), (({:if})), (({:while})), (({:unless})), (({:end})), (({:def})), (({:class})), (({:module})), etc. As with the<br>
identifiers, it should go at the end. So an (({if}))-block would be represented as<br>
[0] :if<br>
[1] CONDITION<br>
[2] BLOCK<br>
[3] [:elsif, ...] || [:else, ...] || nil<br>
[4] [lineNo, colNo] # location of the leading :if/:elsif/:else/:unless</p>
<p>I currently get the first coordinate of ((%CONDITION%)), and then look up the preceding<br>
(({:if}))/(({:elsif}))/(({:else})) using (({Ripper.lex(src).find_all{|posn kwd name| kwd == :on_kw && %w/if else elsif/.include?(name) }}))</p>
<p>So the info is in Ripper. It would be more convenient if I could get that info in the src tree.</p>
<p>Note that my suggestion won't break (most) existing code, as the new data goes at the end<br>
of the list.</p>
<p>The same would be useful for other keywords, including (({:module})) (({:class})) (({:def})) (({:try})) (({:catch})) (({:begin})) (({:rescue})).<br>
=end</p> Ruby master - Feature #8291 (Open): Allow retrieving the root Fiber of a Threadhttps://bugs.ruby-lang.org/issues/82912013-04-19T15:53:51Zhalorgium (Tim Carey-Smith)ruby@spork.in
<p>=begin<br>
Currently (({Thread.backtrace})) returns the stack frames for the currently running (({Fiber})).<br>
It is not possible to retrieve the backtrace.</p>
<p>Building on <a href="http://bugs.ruby-lang.org/issues/8263" class="external">http://bugs.ruby-lang.org/issues/8263</a>, this would allow for this feature.<br>
=end</p> Ruby master - Feature #8275 (Open): Add Module#public_const_gethttps://bugs.ruby-lang.org/issues/82752013-04-16T18:28:56Zrkh (Konstantin Haase)me@rkh.im
<p>Right now, <code>const_get</code> will always return a constant, no matter the visibility, which is probably what we want most of the time. But if you for instance have code that does some automatic name to constant resolution, you might now want to leak private constants.</p>
<p>module Foo<br>
Bar = 42<br>
private_constant :Bar<br>
end</p>
<a name="currently"></a>
<h1 >currently:<a href="#currently" class="wiki-anchor">¶</a></h1>
<p>Foo::Bar # raises NameError<br>
Foo.const_get("Bar") # => 42<br>
Object.const_get("Foo::Bar") # => 42</p>
<a name="proposed"></a>
<h1 >proposed:<a href="#proposed" class="wiki-anchor">¶</a></h1>
<p>Foo.public_const_get("Bar") # raises NameError<br>
Object.public_const_get("Foo::Bar") # raises NameError</p> Ruby master - Feature #8272 (Open): Transfer feature tracking to CommonRubyhttps://bugs.ruby-lang.org/issues/82722013-04-16T05:45:34Zheadius (Charles Nutter)headius@headius.com
<p>If my proposal in <a class="issue tracker-2 status-2 priority-4 priority-default" title="Feature: Proposal for moving to a more visible, formal process for feature requests (Assigned)" href="https://bugs.ruby-lang.org/issues/8271">#8271</a> is accepted, we'll need to:</p>
<ol>
<li>
<p>Document in appropriate places that CommonRuby is the place to file and track feature changes. Examples of such places: bugs.ruby-lang.org top-level page, pages for the existing "trunk" and version-specific Redmine projects, ruby-lang.org pages that describe how to file bugs.</p>
</li>
<li>
<p>Decide how to handle the "feature" flag in the current trackers. This may include solutions like removing it entirely (perhaps infeasible if existing features are not migrated to CommonRuby), adding a warning or error when "feature" is selected to encourage users to file under CommonRuby instead, or automatically putting "feature" issues under CommonRuby at submission time.</p>
</li>
<li>
<p>(optional) Migrate existing open features to CommonRuby.</p>
</li>
</ol> Ruby master - Feature #8259 (Open): Atomic attributes accessorshttps://bugs.ruby-lang.org/issues/82592013-04-12T17:43:20Zfunny_falcon (Yura Sokolov)funny.falcon@gmail.com
<p>Motivated by this gist ((<a href="URL:https://gist.github.com/jstorimer/5298581" class="external">URL:https://gist.github.com/jstorimer/5298581</a>)) and atomic gem</p>
<p>I propose Class.attr_atomic which will add methods for atomic swap and CAS:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"> <span class="k">class</span> <span class="nc">MyNode</span>
<span class="nb">attr_accessor</span> <span class="ss">:item</span>
<span class="n">attr_atomic</span> <span class="ss">:successor</span>
<span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">successor</span><span class="p">)</span>
<span class="vi">@item</span> <span class="o">=</span> <span class="n">item</span>
<span class="vi">@successor</span> <span class="o">=</span> <span class="n">successor</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="n">node</span> <span class="o">=</span> <span class="no">MyNode</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">other_node</span><span class="p">)</span>
<span class="c1"># attr_atomic ensures at least #{attr} reader method exists. May be, it should</span>
<span class="c1"># be sure it does volatile access.</span>
<span class="n">node</span><span class="p">.</span><span class="nf">successor</span>
<span class="c1"># #{attr}_cas(old_value, new_value) do CAS: atomic compare and swap</span>
<span class="k">if</span> <span class="n">node</span><span class="p">.</span><span class="nf">successor_cas</span><span class="p">(</span><span class="n">other_node</span><span class="p">,</span> <span class="n">new_node</span><span class="p">)</span>
<span class="nb">print</span> <span class="s2">"there were no interleaving with other threads"</span>
<span class="k">end</span>
<span class="c1"># #{attr}_swap atomically swaps value and returns old value.</span>
<span class="c1"># It ensures that no other thread interleaves getting old value and setting</span>
<span class="c1"># new one by cas (or other primitive if exists, like in Java 8)</span>
<span class="n">node</span><span class="p">.</span><span class="nf">successor_swap</span><span class="p">(</span><span class="n">new_node</span><span class="p">)</span>
</code></pre>
<p>It will be very simple for MRI cause of GIL, and it will use atomic primitives for<br>
other implementations.</p>
<p>Note: both (({#{attr}_swap})) and (({#{attr}_cas})) should raise an error if instance variable were not explicitly set before.</p>
<p>Example for nonblocking queue: ((<a href="URL:https://gist.github.com/funny-falcon/5370416" class="external">URL:https://gist.github.com/funny-falcon/5370416</a>))</p>
<p>Something similar should be proposed for Structs. May be override same method as (({Struct.attr_atomic}))</p>
<p>Open question for reader:<br>
should (({attr_atomic :my_attr})) ensure that #my_attr reader method exists?<br>
Should it guarantee that (({#my_attr})) provides 'volatile' access?<br>
May be, (({attr_reader :my_attr})) already ought to provide 'volatile' semantic?<br>
May be, semantic of (({@my_attr})) should have volatile semantic (i doubt for that)?</p> Ruby master - Feature #8206 (Open): Should Ruby core implement String#blank? https://bugs.ruby-lang.org/issues/82062013-04-03T09:32:10Zsam.saffron (Sam Saffron)sam.saffron@gmail.com
<p>There has been some discussion about porting the <code>#blank?</code> protocol over to Ruby in the past that has been rejected by Matz.</p>
<p>This proposal is only about <code>String</code> however.</p>
<p>At the moment to figure out if you have a blank string you would</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="s2">" "</span><span class="p">.</span><span class="nf">strip</span><span class="p">.</span><span class="nf">length</span> <span class="o">==</span> <span class="mi">0</span>
</code></pre>
<p>The disadvantage is that this forces unneeded allocations and does too much work:</p>
<p>An optimal implementation would be:</p>
<pre><code class="c syntaxhl" data-language="c"><span class="k">static</span> <span class="n">VALUE</span>
<span class="nf">rb_str_blank</span><span class="p">(</span><span class="n">VALUE</span> <span class="n">str</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">rb_encoding</span> <span class="o">*</span><span class="n">enc</span><span class="p">;</span>
<span class="kt">char</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="o">*</span><span class="n">e</span><span class="p">;</span>
<span class="n">enc</span> <span class="o">=</span> <span class="n">STR_ENC_GET</span><span class="p">(</span><span class="n">str</span><span class="p">);</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">RSTRING_PTR</span><span class="p">(</span><span class="n">str</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">s</span> <span class="o">||</span> <span class="n">RSTRING_LEN</span><span class="p">(</span><span class="n">str</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="n">Qtrue</span><span class="p">;</span>
<span class="n">e</span> <span class="o">=</span> <span class="n">RSTRING_END</span><span class="p">(</span><span class="n">str</span><span class="p">);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">s</span> <span class="o"><</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">cc</span> <span class="o">=</span> <span class="n">rb_enc_codepoint_len</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">,</span> <span class="n">enc</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">rb_isspace</span><span class="p">(</span><span class="n">cc</span><span class="p">)</span> <span class="o">&&</span> <span class="n">cc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="n">Qfalse</span><span class="p">;</span>
<span class="n">s</span> <span class="o">+=</span> <span class="n">n</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">Qtrue</span><span class="p">;</span>
<span class="p">}</span>
</code></pre>
<p>This in turn is about 5-8x than the regex solution to the problem and way faster than allocating one massive string with strip when length is large.</p>
<p>Should Ruby take on this method, to accompany <code>#strip</code> following its practice.</p>
<hr>
<p>A slight caveat though is that active support has a somewhat different definition of blank?</p>
<pre><code class="c syntaxhl" data-language="c"><span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">as_blank</span><span class="p">[</span><span class="mi">26</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">9</span><span class="p">,</span> <span class="mh">0xa</span><span class="p">,</span> <span class="mh">0xb</span><span class="p">,</span> <span class="mh">0xc</span><span class="p">,</span> <span class="mh">0xd</span><span class="p">,</span>
<span class="mh">0x20</span><span class="p">,</span> <span class="mh">0x85</span><span class="p">,</span> <span class="mh">0xa0</span><span class="p">,</span> <span class="mh">0x1680</span><span class="p">,</span> <span class="mh">0x180e</span><span class="p">,</span> <span class="mh">0x2000</span><span class="p">,</span> <span class="mh">0x2001</span><span class="p">,</span>
<span class="mh">0x2002</span><span class="p">,</span> <span class="mh">0x2003</span><span class="p">,</span> <span class="mh">0x2004</span><span class="p">,</span> <span class="mh">0x2005</span><span class="p">,</span> <span class="mh">0x2006</span><span class="p">,</span> <span class="mh">0x2007</span><span class="p">,</span> <span class="mh">0x2008</span><span class="p">,</span>
<span class="mh">0x2009</span><span class="p">,</span> <span class="mh">0x200a</span><span class="p">,</span> <span class="mh">0x2028</span><span class="p">,</span> <span class="mh">0x2029</span><span class="p">,</span> <span class="mh">0x202f</span><span class="p">,</span> <span class="mh">0x205f</span><span class="p">,</span> <span class="mh">0x3000</span>
<span class="p">};</span>
<span class="k">static</span> <span class="n">VALUE</span>
<span class="nf">rb_str_blank_as</span><span class="p">(</span><span class="n">VALUE</span> <span class="n">str</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">rb_encoding</span> <span class="o">*</span><span class="n">enc</span><span class="p">;</span>
<span class="kt">char</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="o">*</span><span class="n">e</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">found</span><span class="p">;</span>
<span class="n">enc</span> <span class="o">=</span> <span class="n">STR_ENC_GET</span><span class="p">(</span><span class="n">str</span><span class="p">);</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">RSTRING_PTR</span><span class="p">(</span><span class="n">str</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">s</span> <span class="o">||</span> <span class="n">RSTRING_LEN</span><span class="p">(</span><span class="n">str</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="n">Qtrue</span><span class="p">;</span>
<span class="n">e</span> <span class="o">=</span> <span class="n">RSTRING_END</span><span class="p">(</span><span class="n">str</span><span class="p">);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">s</span> <span class="o"><</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">cc</span> <span class="o">=</span> <span class="n">rb_enc_codepoint_len</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">,</span> <span class="n">enc</span><span class="p">);</span>
<span class="n">found</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">26</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
<span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">current</span> <span class="o">=</span> <span class="n">as_blank</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">if</span><span class="p">(</span><span class="n">current</span> <span class="o">==</span> <span class="n">cc</span><span class="p">)</span> <span class="p">{</span>
<span class="n">found</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span><span class="p">(</span><span class="n">cc</span> <span class="o"><</span> <span class="n">current</span><span class="p">){</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">found</span><span class="p">)</span> <span class="k">return</span> <span class="n">Qfalse</span><span class="p">;</span>
<span class="n">s</span> <span class="o">+=</span> <span class="n">n</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">Qtrue</span><span class="p">;</span>
<span class="p">}</span>
</code></pre>
<p>Clearly it makes no sense to have such a method.</p>
<p>If Ruby took over implementing <code>String#blank?</code> it would clash with Active Support. But imho would enforce better API consistency.</p>
<p>Thoughts?</p> Ruby master - Bug #8185 (Open): Thread/fork issuehttps://bugs.ruby-lang.org/issues/81852013-03-30T03:33:57ZAnonymous
<p>Hello all,</p>
<p>I've found an issue where calling fork inside a thread, and passing a block<br>
to the fork, causes the forked process to continue after the block. I've<br>
reproduced the issue on the following versions of ruby:<br>
ruby 2.0.0p100 (2013-03-27 revision 39954) [x86_64-darwin10.8.0]<br>
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0]</p>
<p>Here is the script I used to reproduce:</p>
<p>1000.times do |j|<br>
puts "run #{j}"<br>
threads = []<br>
100.times do |i|<br>
threads << Thread.new(i) do |local_i|<br>
opid = fork do<br>
# exit!(true) # fixes the issue<br>
# exit(true) # doesn't fix the issue<br>
# no 'exit' also exhibits issue<br>
end<br>
::Process.waitpid(opid, 0)<br>
File.open("/tmp/test_thread_fork_#{local_i}.pid", "w") {|f| f.write<br>
"1" }<br>
end<br>
end<br>
threads.map { |t| t.join }</p>
<p>borked = false<br>
100.times do |i|<br>
fn = "/tmp/test_thread_fork_#{i}.pid"<br>
contents = File.read(fn)<br>
if contents.size > 1<br>
puts "file #{fn} was written to many times (#{contents})"<br>
borked = true<br>
end<br>
end<br>
exit(false) if borked<br>
end</p>
<p>As you can see from the comments inside the fork I can work around the<br>
issue by using "exit!". I am correct in understanding that there should be<br>
no case in which the file is written to multiple times, correct?</p>
<p>Thank you,<br>
Jason Gladish</p> Ruby master - Feature #8184 (Open): Avoid the creation of meaningless ranges (nil, false, true)https://bugs.ruby-lang.org/issues/81842013-03-29T23:16:36Zphi (Pascal Hurni)hurnip@gmail.com
<p>With the definition of <=> on Object on post 1.8, the range_init() function no more throws "ArgumentError: bad value for range" when creating these ranges:<br>
nil..nil<br>
false..false<br>
true..true</p>
<p>These kind of ranges are meaningless, the majority of methods on Range do not work on them, like (nil..nil).include?(nil).</p>
<p>This feature request (with patch) re-introduces the 1.8 behaviour of throwing ArgumentError when creating such ranges.</p> Ruby master - Feature #8088 (Open): Method#parameters (and friends) should provide useful informa...https://bugs.ruby-lang.org/issues/80882013-03-14T07:56:06Zheadius (Charles Nutter)headius@headius.com
<p>I was wiring up #parameters to work for native methods today when I realized MRI doesn't give very good information about variable-arity native methods:</p>
<pre><code>$ ruby2.0.0 -e "p ''.method(:gsub).to_proc.parameters"
[[:rest]]
$ jruby -e "p ''.method(:gsub).to_proc.parameters"
[[:req], [:opt]]
</code></pre>
<p>I think MRI should present the same as JRuby here; gsub is obviously not a rest-arg method and you can't call it with less than 1 or more than 2 arguments. JRuby's presenting the right output here.</p>
<p>I'm probably going to have to change JRuby to do the less-helpful version so we're compliant and tests pass, but I think the specification of #parameters should be that it presents the JRuby version about rather than the MRI version.</p> Ruby master - Feature #8046 (Open): allow Object#extend to take a blockhttps://bugs.ruby-lang.org/issues/80462013-03-08T11:48:34Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<p>=begin<br>
In <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Keyword `object` to be used instead of `class <<` (Rejected)" href="https://bugs.ruby-lang.org/issues/8038">#8038</a> david_macmahon proposed:</p>
<p>How about allowing Object#extend to take a block that would be executed with the context such that methods defined therein would become singleton methods of the object receiving #extend?</p>
<p>For example:<br>
foo = Object.new<br>
foo.extend do<br>
def bar<br>
# ...<br>
end<br>
def baz<br>
# ...<br>
end<br>
end<br>
=end</p> Ruby master - Feature #7981 (Open): ruby does not respect --https://bugs.ruby-lang.org/issues/79812013-02-28T08:40:08Zmpapis (Michal Papis)mpapis@gmail.com
<p>=begin<br>
in ((%ruby --help%)) I have found:</p>
<pre><code>Usage: ruby [switches] [--] [programfile] [arguments]
</code></pre>
<p>so I have tried this example:</p>
<pre><code>$ echo 'puts :ok' | ruby -- --params
> ruby: No such file or directory -- --params (LoadError)
</code></pre>
<p>I have assumed that ((%[argumments]%)) are independent from ((%[programfile]%))</p>
<p>In the current state of code the help message should be:</p>
<pre><code>Usage: ruby [switches] [--] [programfile [arguments]]
</code></pre>
<p>But I would prefer that it would be fixed and anything after ((%[--]%)) that is not program gets ignored, so we can use the shell style:</p>
<pre><code>$ echo 'echo "args:$*:"' | bash -s -- --params
> args:--params:
</code></pre>
<p>=end</p> Ruby master - Feature #7895 (Open): Exception#backtrace_locations to go with Thread#backtrace_loc...https://bugs.ruby-lang.org/issues/78952013-02-21T06:02:25Zheadius (Charles Nutter)headius@headius.com
<p>Thread#backtrace_locations and Kernel#caller_locations were added in Ruby 2.0.0, but no equivalent method was added to Exception to get backtrace locations. The String format of Exception#backtrace elements makes it difficult to do any inspection of the actual files and lines it reports, so having backtrace_locations would be very useful.</p>
<p>In <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Exceptions should have backtrace_locations (Rejected)" href="https://bugs.ruby-lang.org/issues/7435">#7435</a> ko1 pointed out that Exception defines set_backtrace, which takes an array (presumably of Strings in the same format as Exception#backtrace) and that this would need to be addressed in order to support backtrace_locations. I propose that if you set_backtrace, you are already breaking the ability to get structured Location elements, so set_backtrace should cause backtrace_locations to return nil or an empty array (probably an empty array, so it can always be expected to be non-nil).</p>
<p>We could consider also adding set_backtrace_locations as a way to set Location elements into the exception.</p>
<p>An example script where backtrace_locations would be very useful is here (avoiding the need to regexp match to get file and line number): <a href="https://gist.github.com/headius/4999244" class="external">https://gist.github.com/headius/4999244</a></p> Ruby master - Feature #7845 (Open): Strip doesn't handle unicode space characters in ruby 1.9.2 &...https://bugs.ruby-lang.org/issues/78452013-02-14T00:27:55Ztimothyg56 (Timothy Garnett)timothyg@alum.mit.edu
<p>Strip and associated methods in ruby 1.9.2 and 1.9.3 do not remove leading/trailing unicode space characters (such as non-breaking space \u00A0 and ideographic space \u3000) unlike ruby 1.9.1. I'd expect the 1.9.1 behavior. Looking at the underlying native lstrip! and rstrip! methods it looks like this is because 1.9.1 uses rb_enc_isspace() whereas 1.9.2+ uses rb_isspace().</p>
<p>1.9.1p378 :001 > "\u3000\u00a0".strip<br>
=> ""</p>
<p>1.9.2p320 :001 > "\u3000\u00a0".strip<br>
=> " "</p>
<p>1.9.3p286 :001 > "\u3000\u00a0".strip<br>
=> " "</p> Ruby master - Feature #7747 (Open): Expanded API for Binding semanticshttps://bugs.ruby-lang.org/issues/77472013-01-28T08:08:12Zjballanc (Joshua Ballanco)jballanc@gmail.com
<p>=begin<br>
Currently, the only way to create a new instance of Binding is to get a copy of the current scope's binding, or ask some other object for its binding. In either case, the binding object returned always has semantics identical to the original binding. In other words, a binding object used with eval is capable of (not necessarily an exhaustive list):</p>
<ul>
<li>redefining methods on the binding target</li>
<li>defining new methods on the binding target</li>
<li>getting/setting instance variables</li>
<li>getting/creating new constants</li>
</ul>
<p>This feature proposal would introduce a new mechanism for creating a binding and adjusting its relationship with the source binding. For example, if you have a class (({Foo})) defined like so:</p>
<pre><code>class Foo
def say
puts "hello!"
end
end
</code></pre>
<p>Then you would be able to create a new binding that ((<em>won't</em>)) propagate new definitions to the parent binding like so:</p>
<pre><code>new_binding = Binding.new(Foo)
new_binding.propagate = false
new_binding.eval("def shout; puts 'HI!'; end")
Foo.new.say #=> "hello!"
Foo.new.shout #=> No Method Error
new_binding.eval("Foo.new.say") #=> "hello"
new_binding.eval("Foo.new.shout") #=> "HI!"
</code></pre>
<p>If, additionally, we introduce a way to merge or combine bindings, then this API could actually be used to implement refinements in pure Ruby like so (note I am also assuming that (({Binding#eval})) gains the ability to take a block):</p>
<pre><code>class Module
def refine(klass, &block)
@refined_bindings ||= {}
refinement_binding = Binding.new(klass)
refinement_binding.propagate = false
refinement_binding.shadow = true
refinement_binding.eval &block
(@refined_bindings[self.name] ||= []) << refinement_binding
end
def using(mod)
@refined_bindings[mod].each { |refinement| self.binding.merge(refinement) }
end
end
</code></pre>
<p>Following is the preliminary list of additional APIs I am tentatively proposing (though I expect this to change with additional discussion):</p>
<ul>
<li>(({Binding.new(an_object)})) - creates a new Binding object that "inherits" the binding of the argument; essentially equivalent to (({an_object.send(:binding).dup}))</li>
<li>(({Binding#propagate}))/(({Binding#propagate=})) - boolean; determines whether new method, class, or Constant defs are propagated into the "parent" binding's scope</li>
<li>(({Binding#shadow}))/(({Binding#shadow=})) - boolean; sets whether or not new values for existing methods/constants/variables can be set</li>
<li>(({Binding#freeze})) - causes the Binding to capture all existing methods/constants/variables in scope at call time, and "disconnect" from the parent binding, so that any updates to definitions or values are no longer reflected into the "child" binding</li>
<li>(({Binding#merge(other_binding)})) - combines the method/constant/variable bindings in (({other_binding})) with the receiver; effectively shadows the "parent" of (({other_binding})) within the receiver binding<br>
=end</li>
</ul> Ruby master - Feature #7708 (Open): support for patches listhttps://bugs.ruby-lang.org/issues/77082013-01-17T04:39:42Zmpapis (Michal Papis)mpapis@gmail.com
<p>Often as maintainer of RVM I have to work with multiple ruby patches, but it's hard to tell what patches were used for compiling ruby. As a temporary solution I have started using a file <code>patches.list</code> in the root of source and installation directory. It would be nice if Ruby would include this list also in RbConfig::CONFIG.</p>
<p>Here is example content of the file I have for ruby-1.9.3-p362:</p>
<pre><code>ruby-multilib
segfault_fix_7629
</code></pre>
<p>If that would be implemented I could understand if it would be required the files to be URLs to online patches which can be easily downloaded and analyzed.</p> Ruby master - Feature #7545 (Open): Make Range act as a "lazy ordered set"https://bugs.ruby-lang.org/issues/75452012-12-12T01:05:47Zalexeymuranov (Alexey Muranov)
<p>=begin</p>
<a name="Make-Range-act-as-a-lazy-ordered-set"></a>
<h1 >Make Range act as a "lazy ordered set"<a href="#Make-Range-act-as-a-lazy-ordered-set" class="wiki-anchor">¶</a></h1>
<p>This replaces my older feature request <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Redefine Range class and introduce RelativeNumeric and RelativeRange (Rejected)" href="https://bugs.ruby-lang.org/issues/5534">#5534</a>.</p>
<p>I propose the following new behavior of (({Range})):</p>
<p>(1..3).to_a # => [1, 2, 3]<br>
(3..1).to_a # => [3, 2, 1]<br>
'a'..'c'.to_a # => ['a', 'b', 'c']<br>
'c'..'a'.to_a # => ['c', 'b', 'a']<br>
1...1 == 3...3 # => true<br>
1...1 == 'a'...'a' # => true<br>
1...1 == Range::EMPTY_SET # => true<br>
1..2 == 1...3 # => false<br>
1...3.include?(2.5) # => true</p>
<p>Also, maybe in the future the following behavior can be possible:</p>
<p>r1 = Range.new('a', 'bc', :deglex)<br>
r1.include?('abc') # => false<br>
r1.to_a # => ['a', 'b', ..., 'az', 'ba', 'bb', 'bc']<br>
r2 = Range.new('a', 'bc', :lex)<br>
r2.include?('abc') # => true<br>
r2.to_a # => Error</p>
<p>and this:</p>
<p>((0.5)..(5.5)).to_a(Integer) # => [1, 2, 3, 4, 5]<br>
((0.5)..(5.5)).each(Integer) do |i| puts i end</p>
<p>(i imagine this would require additions to the (({Integer})) class, so that it<br>
know more about "real" ranges).</p>
<p>=end</p> Ruby master - Feature #7384 (Open): Rename #each_with_object to #each_withhttps://bugs.ruby-lang.org/issues/73842012-11-18T20:12:53Ztrans (Thomas Sawyer)
<p>I propose that #each_with_object be renamed to #each_with, for the following reasons:</p>
<ol>
<li>
<p>The original name is too long. When general purpose methods have long names it tends to deter developers from using them even when they are a good fit to the use case.</p>
</li>
<li>
<p>The last word, "object", is completely redundant. All methods that take an argument could say the same thing. e.g. Array#push is not named #push_object though that is obviously what it means.</p>
</li>
<li>
<p>The change need not effect backward compatibility b/c #each_with_object can remain an alias of #each_with for as long as deemed necessary.</p>
</li>
</ol> Ruby master - Feature #7341 (Open): Enumerable#associatehttps://bugs.ruby-lang.org/issues/73412012-11-13T08:29:55Znathan.f77 (Nathan Broadbent)nathan.f77@gmail.com
<p>Jeremy Kemper proposed Enumerable#associate during the discussion in <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: map_to alias for each_with_object (Rejected)" href="https://bugs.ruby-lang.org/issues/7297">#7297</a>, with the following details:</p>
<hr>
<p>Some background:</p>
<p><a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Enumerable#categorize (Rejected)" href="https://bugs.ruby-lang.org/issues/4151">#4151</a> proposes an Enumerable#categorize API, but it's complex and hard to understand its behavior at a glance.<br>
<a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Enumerable#to_h (Closed)" href="https://bugs.ruby-lang.org/issues/7292">#7292</a> proposes an Enumerable#to_h == Hash[...] API, but I don't think of association/pairing as explicit coercion, so #to_h feels misfit.</p>
<p>Associate is a simple verb with unsurprising results. It doesn't introduce ambiguous "map" naming. You associate an enumerable of keys with yielded values.</p>
<p>Some before/after examples:</p>
<p>Before: Hash[ filenames.map { |filename| [ filename, download_url(filename) ]}]<br>
After: filenames.associate { |filename| download_url filename }</p>
<a name="gt-foojpggthttp-"></a>
<h1 >=> {"foo.jpg"=>"http://...", ...}<a href="#gt-foojpggthttp-" class="wiki-anchor">¶</a></h1>
<p>Before: alphabet.each_with_index.each_with_object({}) { |(letter, index), hash| hash[letter] = index }<br>
After: alphabet.each_with_index.associate</p>
<a name="gt-agt0-bgt1-cgt2-dgt3-egt4-fgt5-"></a>
<h1 >=> {"a"=>0, "b"=>1, "c"=>2, "d"=>3, "e"=>4, "f"=>5, ...}<a href="#gt-agt0-bgt1-cgt2-dgt3-egt4-fgt5-" class="wiki-anchor">¶</a></h1>
<p>Before: keys.each_with_object({}) { |k, hash| hash[k] = self[k] } # a simple Hash#slice<br>
After: keys.associate { |key| self[key] }</p>
<hr>
<p>It's worth noting that this would compliment ActiveSupport's Enumerable#index_by method: <a href="http://api.rubyonrails.org/classes/Enumerable.html#method-i-index_by" class="external">http://api.rubyonrails.org/classes/Enumerable.html#method-i-index_by</a><br>
#index_by produces '{ => el, ...}', while #associate would produce '{el => , ...}'.</p>
<p>For cases where you need to control both keys and values, you could use '[1,2,3].map{|i| [i, i * 2] }.associate', or continue to use 'each_with_object({})'.</p> Ruby master - Feature #7340 (Open): 'each_with' or 'into' alias for 'each_with_object'https://bugs.ruby-lang.org/issues/73402012-11-13T08:17:25Znathan.f77 (Nathan Broadbent)nathan.f77@gmail.com
<p>Following on from the discussions at <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: map_to alias for each_with_object (Rejected)" href="https://bugs.ruby-lang.org/issues/7297">#7297</a> and <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Enumerable#to_h proposal (Rejected)" href="https://bugs.ruby-lang.org/issues/7241">#7241</a>, it is apparent that a shorter alias for 'each_with_object' would be much appreciated.</p> Ruby master - Feature #7250 (Open): A mechanism to include at once both instance-level and class-...https://bugs.ruby-lang.org/issues/72502012-10-31T18:59:56Zalexeymuranov (Alexey Muranov)
<p>=begin<br>
I have simply commented first on <a class="issue tracker-2 status-7 priority-4 priority-default closed" title="Feature: Inheritable #included/#extended Hooks For Modules (Feedback)" href="https://bugs.ruby-lang.org/issues/7240">#7240</a>, but i feel i need to start a ticket in order to not post off topic.</p>
<p>This seems to be a big feature request, so i didn't feel confident to suggest, but when i read in <a class="issue tracker-2 status-7 priority-4 priority-default closed" title="Feature: Inheritable #included/#extended Hooks For Modules (Feedback)" href="https://bugs.ruby-lang.org/issues/7240">#7240</a> that (({Module#included})) hook can become even more hooked, i've decided to express myself.</p>
<p>=== Proposal</p>
<p>In my opinion, the most common use case for the "(({included}))" hook in modules is adding class methods. However, to me this looks hackish and hard to follow. I would have preferred if there was a way to define both instance-level and class-level behavior in a module and include both at once. Here is an API i would suggest:</p>
<p>module M<br>
def foo<br>
'Foo'<br>
end</p>
<pre><code>def base.bar # here a fictional private method Module#base is called
'Bar'
end
</code></pre>
<p>end</p>
<p>class C<br>
include M<br>
end</p>
<p>a = C.new<br>
a.foo # => 'Foo'<br>
C.bar # => 'Bar'</p>
<p>This means that a module would need to store 2 method tables, one as usual, and a second one defined as singleton methods on some object returned by some private method, called for example (({Module#base})). Since ordinary objects have no method table, classes have one method table, why not to allow modules to have 2 method tables?</p>
<p>=== Relevant considerations</p>
<ol>
<li>
<p>Talking about method tables, maybe if objects were allowed to have one, there would be no need for meta-classes? (Then classes would have 2 method tables, modules would have 3, and in fact methods and method tables could be regarded as kinds of attributes.) It looks to me like meta-class is simply there to make up for the fact that objects are not allowed to keep their own methods.</p>
</li>
<li>
<p>Allowing modules to have more method tables than classes may look like breaking the inheritance (({Class < Module})), but to me this inheritance does not look like a good idea anyway. For example, a module can be included, but a class cannot. To me, class looks like an object factory, but a module like a container of parts that can be unpacked and mounted onto a class.</p>
</li>
</ol>
<p>=== Irrelevant considerations</p>
<p>I think that from the point of view of English, the method name "(({included}))" is not consistent with the method name "(({extended}))" (the <em>module</em> is included, but the <em>base</em> is extended).</p>
<p>I would have preferred if the word "(({extend}))" was used instead of "(({include}))" when "including" one module into another, as this operation seems somewhat different from including a module into a class. I understand that it makes no sense to discuss this now, when (({extend})) is already has its fixed meaning.<br>
=end</p> Ruby master - Feature #7220 (Open): Separate IO#dup, StringIO#initialize_copy from dup(2)https://bugs.ruby-lang.org/issues/72202012-10-27T03:38:14Zbrixen (Brian Shirai)brixen@gmail.com
<p>Calling StringIO#initialize_copy causes the two objects to share the position, and eof status.</p>
<p>Is this a bug?</p>
<p>sasha:rubinius brian$ irb<br>
1.9.3p286 :001 > require 'stringio'<br>
=> true<br>
1.9.3p286 :002 > a = StringIO.new "abcdefuq"<br>
=> #<a href="StringIO:0x00000101016a88" class="external">StringIO:0x00000101016a88</a><br>
1.9.3p286 :003 > b = StringIO.new<br>
=> #<a href="StringIO:0x00000101010728" class="external">StringIO:0x00000101010728</a><br>
1.9.3p286 :004 > b.send :initialize_copy, a<br>
=> #<a href="StringIO:0x00000101010728" class="external">StringIO:0x00000101010728</a><br>
1.9.3p286 :005 > a.pos<br>
=> 0<br>
1.9.3p286 :006 > b.pos<br>
=> 0<br>
1.9.3p286 :007 > b.getc<br>
=> "a"<br>
1.9.3p286 :008 > a.pos<br>
=> 1<br>
1.9.3p286 :009 > a.getc<br>
=> "b"<br>
1.9.3p286 :010 > b.pos<br>
=> 2<br>
1.9.3p286 :011 > b.read<br>
=> "cdefuq"<br>
1.9.3p286 :012 > a.eof?<br>
=> true</p>
<p>Thanks,<br>
Brian</p> Ruby master - Feature #7106 (Open): FileUtils.touch should allow touching the symlink itself rath...https://bugs.ruby-lang.org/issues/71062012-10-04T19:32:57Zcirrusthinking (Alessandro Diaferia)alessandro@cirrusthinking.eu
<p>Most systems support POSIX lutimes sys call that allows a symlink to be touched. I'd like to see this feature implemented.<br>
Unfortunately I'd like to see this feature on Solaris as soon as possible but I cannot see lutimes syscall supported there.</p> Ruby master - Feature #7082 (Open): Process.kill 0 in windows can return spurious successhttps://bugs.ruby-lang.org/issues/70822012-09-28T16:29:13Zrogerdpack (Roger Pack)rogerpack2005@gmail.com
<blockquote>
<blockquote>
<p>a = IO.popen('ls "."', 'w')<br>
=> #<IO:fd 4><br>
a.pid<br>
=> 2104<br>
Process.kill 0, 2104<br>
=> 1 # should raise an exception since that process is dead now, shouldn't it? [it can be checked with GetExitCodeProcess != STILL_ACTIVE) ?</p>
</blockquote>
</blockquote>
<p>Thanks!<br>
-r</p> Ruby master - Feature #7060 (Open): Broaden support for chmodhttps://bugs.ruby-lang.org/issues/70602012-09-24T03:10:54Ztonysidaway (Tony Sidaway)tonysidaway@gmail.com
<p>Currently file permission bit features in all Ruby versions include only chmod and (if supported by the target platform's C library) lchmod. lchmod is not supported by all platforms, but where it is not the Posix function fchmodat usually supplies similar functionality. Suggest that this be included.</p>
<p>See <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html" class="external">http://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html</a></p> Ruby master - Feature #6946 (Open): FIPS support?https://bugs.ruby-lang.org/issues/69462012-08-28T21:31:30Zvo.x (Vit Ondruch)v.ondruch@tiscali.cz
<p>=begin<br>
Hi, running the test suite on FIPS enabled system using</p>
<p>$ find test/ -type f -name test_*.rb -exec make test-all TESTS="-v '{}'" ;</p>
<p>command with patch from <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: [PATCH] Increase DH key size to fix test suite in FIPS mode (Closed)" href="https://bugs.ruby-lang.org/issues/6938">#6938</a> applied, it gives me a plenty of errors (see attached output.txt file). There are two kind of errors as far as I understand, some are more or less test suite errors (e.g. <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: [PATCH] Increase DH key size to fix test suite in FIPS mode (Closed)" href="https://bugs.ruby-lang.org/issues/6938">#6938</a>), which should be easy to fix, while some others (e.g. <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: pstore in FIPS mode (Closed)" href="https://bugs.ruby-lang.org/issues/6943">#6943</a>) would need bigger changes.</p>
<p>Is there any chance that Ruby will provide better support for FIPS and there errors get fixed?<br>
=end</p> Ruby master - Feature #6828 (Open): Constancy of Constantshttps://bugs.ruby-lang.org/issues/68282012-08-04T01:23:08Ztrans (Thomas Sawyer)
<p>=begin<br>
Could have swore there was a recent issue addressing this, but couldn't find it, so...</p>
<p>I hope by Ruby 2.0</p>
<p>module Foo::Bar::Baz</p>
<p>will be equivalent to</p>
<p>module Foo; module Bar; module Baz</p>
<p>That constant lookup doesn't work the same for both is really really really annoying.<br>
=end</p> Ruby master - Feature #6783 (Open): Infinite loop in inspect, not overriding inspect, to_s, and n...https://bugs.ruby-lang.org/issues/67832012-07-23T23:22:31Zgarysweaver (Gary Weaver)garysweaver@gmail.com
<p>In Ruby 1.9.3p194 in Rails 3.2.6 in rails console, in my script I'm calling inspect on a Ruby object and even though I'm not overriding inspect, to_s, and there are no known circular references, inspect is going into an infinite loop locking Ruby up with 100% CPU usage.</p>
<p>At first, I would think this problem is probably outside of Ruby and either in my code or in a gem that I'm using, however the problem is that using the Debugger gem, if I set a breakpoint above the issue and use "s" (by itself) to step into the line where it calls inspect, it locks up there, so I can't debug the issue. When I do that I hit ctrl-c, I'm in .../.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:</p>
<pre><code> 64 trap("SIGINT") do
=> 65 irb.signal_handle
66 end
</code></pre>
<p>and breaking out of that, or if I don't step into it and I break out of it, I see:</p>
<pre><code>path_to_script/script_name.rb:739:in `call'
path_to_script/script_name.rb:739:in `inspect'
path_to_script/script_name.rb:739:in `inspect'
...
(~100 times)
path_to_script/script_name.rb:739:in `block (2 levels) in my_method_name'
</code></pre>
<p>In a situation like this, how can I debug the issue? Is there anything in the inspect method that could causing this behavior?</p>
<p>I think the most likely culprit is some bad code on my part in the script, but unfortunately I can't debug it when the debugger can't step into inspect.</p>
<p>Thanks for any help you can provide.</p> Ruby master - Feature #6758 (Open): Object#sequencehttps://bugs.ruby-lang.org/issues/67582012-07-20T13:38:09Zmerborne (kyo endo)
<p>=begin</p>
<p>== Object#sequence</p>
<p>Let me propose a new method ((<em>Object#sequence</em>)).</p>
<p>次のような実装の((<em>Object#sequence</em>))を提案します。</p>
<pre><code>class Object
def sequence(init=true, &blk)
x = self
Enumerator.new do |y|
y << x if init
loop { y << (x = yield x) }
end
end
end
</code></pre>
<p>((<em>sequence</em>)) generate a sequence by applying a block recursively to the receiver object. The result is wrapped with a Enumerator object, thus it is set under lazy evaluation.</p>
<p>((<em>sequence</em>))は、そのレシーバオブジェクトを初期値として、渡されたブロック(漸化式)を繰り返し適用してシーケンスを生成します。適用の結果はEnumeratorオブジェクトでラップされているので、遅延評価されます。</p>
<p>== Usage;</p>
<p>使い方を示します。</p>
<pre><code>1.sequence { |x| x + 2 }.take(10) # => [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
3.sequence { |x| x * 2 }.take(10) # => [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536]
[0, 1].sequence { |a, b| [b, a + b] }.take(10).map(&:first) # => [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
[0, 1, 1].sequence { |a, b, c| [b, c, a + b + c] }.take(10).map(&:first) # => [0, 1, 1, 2, 4, 7, 13, 24, 44, 81]
# square root 5
a = 5
eps = 0.0001
1.0.sequence { |x| (x + a/x) / 2.0 }
.each_cons(2)
.detect { |a, b| (a - b).abs < eps }[1] # => 2.236067977499978
# Excel label
'A'.sequence { |x| x.succ }.take(30) # => ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD"]
# random boolean(avoid true-true sequence)
true.sequence { |prev| prev ? false : [true, false].sample }.take(20) # => [true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, false, false, true, false]
</code></pre>
<p>== Some background</p>
<p>== 提案の経緯</p>
<p>Let me explain some background of this request.</p>
<p>本件に関しては、ここに至る若干の経緯がありますので、併せて説明します。</p>
<ol>
<li>
<p>I introduced this method as ((<em>Object#repeat</em>)) on my Japanese blog.</p>
</li>
<li>
<p>私のブログにおいて、本メソッドを((<em>Object#repeat</em>))として紹介する記事を公開。</p>
</li>
</ol>
<p>((<a href="URL:http://melborne.github.com/2012/07/12/object-repeat-take-care-of-sequence/" class="external">URL:http://melborne.github.com/2012/07/12/object-repeat-take-care-of-sequence/</a>))</p>
<ol start="2">
<li>
<p>Matz tweeted to the article.</p>
<blockquote>
<p>"um.. the feature is attractive, but the name is.."</p>
</blockquote>
</li>
<li>
<p>記事に対してMatzがつぶやく。</p>
<blockquote>
<p>「うーん、昨日としては魅力的だけど、名前がなあ。」</p>
</blockquote>
</li>
</ol>
<p>((<a href="URL:https://twitter.com/yukihiro_matz/status/223790181113806848" class="external">URL:https://twitter.com/yukihiro_matz/status/223790181113806848</a>))</p>
<ol start="3">
<li>
<p>I updated the article to propose ((<em>Object#repeat_apply</em>)) or ((<em>Object#repeat_call</em>)).</p>
</li>
<li>
<p>Object#repeat_apply, Object#repeat_callを提案するべく記事を更新。</p>
</li>
<li>
<p>Matz tweeted to the article.</p>
<blockquote>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/4653">@merborne (kyo endo)</a> more clear. but combining two verbs is wrong. I understand naming is difficult.</p>
</blockquote>
</li>
<li>
<p>記事に対してMatzがつぶやく。</p>
<blockquote>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/4653">@merborne (kyo endo)</a> なるほど「repeat_apply」か「repeat_call」ですか。repeat単体よりは誤解を受けにくいとは思いますが、repeatって動詞とapply/callって動詞の組み合わせは感心しませんね。名前って難しい。</p>
</blockquote>
</li>
</ol>
<p>((<a href="URL:https://twitter.com/yukihiro_matz/status/224105896110866432" class="external">URL:https://twitter.com/yukihiro_matz/status/224105896110866432</a>))</p>
<ol start="5">
<li>
<p>Matz tweeted to the article.</p>
<blockquote>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/4653">@merborne (kyo endo)</a> I suggest some clue lies around a word "series"..</p>
</blockquote>
</li>
<li>
<p>記事に対してMatzがつぶやく。</p>
<blockquote>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/4653">@merborne (kyo endo)</a> 「級数/series」あたりに名前のヒントがありそうな。</p>
</blockquote>
</li>
</ol>
<p>((<a href="URL:https://twitter.com/yukihiro_matz/status/224106160591081472" class="external">URL:https://twitter.com/yukihiro_matz/status/224106160591081472</a>))</p>
<ol start="6">
<li>
<p>I tweeted to Matz.</p>
</li>
<li>
<p>私もつぶやく</p>
<blockquote>
<p>@yukihiro_matz you are right.. <code>repeated_apply</code> <code>repeated_call</code>?..</p>
</blockquote>
<blockquote>
<p>@yukihiro_matz たしかに.. repeated_apply repeated_callかな..</p>
</blockquote>
</li>
</ol>
<p>((<a href="URL:https://twitter.com/merborne/status/224108387653259264" class="external">URL:https://twitter.com/merborne/status/224108387653259264</a>))</p>
<pre><code>> @yukihiro_matz clue! `series_by` ?
> @yukihiro_matz ヒント! series_by ?
</code></pre>
<p>((<a href="URL:https://twitter.com/merborne/status/224108809948377088" class="external">URL:https://twitter.com/merborne/status/224108809948377088</a>))</p>
<pre><code>> @yukihiro_matz `repeated` is adjective..^^; but I don't like `repeatedly_apply`. I thought once `series_by` is good, but it would be better a method is named based on its behavior, not on its function, I think. How about `repeat_by`?
> @yukihiro_matz repeatedは形容詞でしたね^^; するとrepeatedly_applyですが、今ひとつです。series_byもいいと思ったんですが、できれば機能ではなく動作を言いたい思いがあります。そこでrepeat_byというのはどうでしょうか。
</code></pre>
<p>((<a href="URL:https://twitter.com/merborne/status/224324670764220416" class="external">URL:https://twitter.com/merborne/status/224324670764220416</a>))</p>
<p>the conversation closed..</p>
<p>会話終了..</p>
<ol start="7">
<li>Ideas from other Rubyists</li>
</ol>
<p>Some Japanese Rubyists tweeted or commented me on the name. Candidates are..</p>
<ol start="7">
<li>他のRubyistの意見</li>
</ol>
<p>名前に関し何人かのRubyistからアイディアをもらっています。リストアップします。</p>
<pre><code>iterate
recur
recurrence
recur_with
unfold
sequence
seq
</code></pre>
<p>Haskell and Scala have the same functionality with a name of ((<em>iterate</em>)).</p>
<p>なお、HaskellとScalaには同種の機能が、((<em>iterate</em>))という名前で実装されているそうです。</p>
<p>Also, @makotokuwata-san tweeted that ((<em>Kernel#seq</em>))(function style) or ((<em>Enumerator.seq()</em>))(a Class method) is better.</p>
<p>また、@makotokuwata氏よりKernel#seqのような関数形式か、Enumerator.seq()のようなクラスメソッドのほうがいいとの意見も頂いています。</p>
<pre><code>> @yukihiro_matz @merborne 初期値と漸化式から順列を作る機能なので、"sequence"か"seq"に1票。あとKernel#seq(initial,&blk)のほうが好きです。RT 「級数/series」あたりに名前のヒントがありそうな。
</code></pre>
<p>((<a href="URL:https://twitter.com/makotokuwata/status/225806204390227968" class="external">URL:https://twitter.com/makotokuwata/status/225806204390227968</a>))</p>
<p>Thank you for your consideration.</p>
<p>以上、ご検討のほどよろしくお願い致します。</p>
<p>=end</p> Ruby master - Feature #6733 (Open): New inspect frameworkhttps://bugs.ruby-lang.org/issues/67332012-07-14T18:06:18Zakr (Akira Tanaka)akr@fsij.org
<p>After we discussed <a href="http://bugs.ruby-lang.org/issues/6291" class="external">http://bugs.ruby-lang.org/issues/6291</a> at a developer meeting,<br>
we re-realized new inspect framework may be useful.</p>
<p>Problem:</p>
<ul>
<li>inspect method may generate too long string but sometimes whole string is not required.<br>
For example, first 70 characters are enough for error messages (backtrace).</li>
<li>inspect can't know a encoding to be expected.</li>
<li>inspect generates may short strings and discard them immediately.</li>
</ul>
<p>If we have a new method, inspect_to(buffer), and<br>
it (or overridden method in subclass) adds the inspected result to buffer,<br>
we can solve above problems.<br>
buffer has a method, <<.<br>
It may be a string, IO or other object.</p>
<p>For too long string, buffer itself can throw (or raise) when buffered output is reached to a specified limit.</p>
<p>For encoding, buffer can record an encoding.<br>
(p method creates a buffer object using $stdout's encoding.)</p>
<p>For small strings, in C level, we can create a rb_buffer_add(VALUE buffer, const char *p, long len) and<br>
it don't need to allocate a String object.</p>
<p>This is big change but we can preserve compatibility by following default inspect_to method:</p>
<p>class Object<br>
def inspect_to(buffer)<br>
buffer << self.inspect<br>
end<br>
end</p>
<p>If legacy class which has inspect but not inspect_to,<br>
Object#inspect_to calls inspect and use the result.</p> Ruby master - Feature #6687 (Open): Enumerable#withhttps://bugs.ruby-lang.org/issues/66872012-07-02T22:38:59Zmerborne (kyo endo)
<p>=begin<br>
Let me propose <code>Enumerable#with</code> for an alias of <code>Enumerable#each_with_object</code> or replace of it.</p>
<p><code>Enumerable#each_with_object</code>のエイリアス、またはその置き換えとして、<code>Enumerable#with</code>を提案します。</p>
<p>##Reason</p>
<p>##理由</p>
<p>When you create a hash using <code>Enumerable#inject</code>, you should ensure that the block return the hash.</p>
<p><code>Enumerable#inject</code>を使ってハッシュを生成するときには、ブロックの返り値としてハッシュが返ることを保証する必要があります。</p>
<pre><code>words.inject(Hash.new(0)) { |h, word| h[word] += 1; h } # => {"You"=>3, "say"=>10, "Yes"=>1, "I"=>7, "No"=>1, "Stop"=>1, "and"=>2, "Go"=>1, "go"=>2, "Oh"=>1, "no"=>1, "Goodbye"=>2, "Hello"=>2, "hello"=>5, "don"=>2, "t"=>2, "know"=>2, "why"=>2, "you"=>2, "goodbye"=>1}
</code></pre>
<p>Many rubyists, however, hate this, and there are many discussions for it.</p>
<p>しかし、これを嫌うRubyistは多く、ネット上でその改善についての議論をしばしば見掛けます。</p>
<pre><code>Feature #5662: inject-accumulate, or Haskell's mapAccum* - ruby-trunk - Ruby Issue Tracking System http://bugs.ruby-lang.org/issues/5662
Ruby inject with intial being a hash - Stack Overflow http://stackoverflow.com/questions/9434162/ruby-inject-with-intial-being-a-hash
</code></pre>
<p><code>Enumerable#each_with_object</code> is often presented for one of the best solutions for it.</p>
<p>そしてその有力な解決策として、Enumerable#each_with_objectが提示されてきました。</p>
<pre><code>words.each_with_object(Hash.new(0)) { |word, h| h[word] += 1 } # => {"You"=>3, "say"=>10, "Yes"=>1, "I"=>7, "No"=>1, "Stop"=>1, "and"=>2, "Go"=>1, "go"=>2, "Oh"=>1, "no"=>1, "Goodbye"=>2, "Hello"=>2, "hello"=>5, "don"=>2, "t"=>2, "know"=>2, "why"=>2, "you"=>2, "goodbye"=>1}
</code></pre>
<p>However, <code>each_with_object</code> is still unfamiliar and then not used frequently. The biggest reason, I think, is its lengthy name.</p>
<p>しかし、その有用性にも拘らず、依然としてeach_with_objectの知名度および利用頻度は低いと思われます。そして、その原因は、その名前の長さにあると考えます。</p>
<p><code>each_with_object</code> is the 39th longest-name method among 754 at Ruby 1.9.3, based on following calculation;</p>
<p>以下の演算により、Ruby1.9.3の環境下でeach_with_objectは、754件中39番目に長い名前のメソッドであることが分かりました。</p>
<pre><code>methods = Module.constants.flat_map do |c|
next [] if c == :Gem
k = Module.const_get(c)
k.methods(false) + k.instance_methods(false) rescue []
end.uniq.reject { |m| "#{m}".start_with? '_deprecated' }.sort_by { |m| -m.size }
methods.size # => 754
methods.index(:each_with_object) # => 39
puts methods.take(100).group_by(&:size).to_a
</code></pre>
<p>The output is here.</p>
<p>出力です。</p>
<pre><code>26
protected_instance_methods
instance_variable_defined?
25
protected_method_defined?
24
private_instance_methods
23
class_variable_defined?
public_instance_methods
define_singleton_method
private_method_defined?
22
singleton_method_added
public_instance_method
public_method_defined?
21
instance_variable_get
instance_variable_set
remove_class_variable
20
private_class_method
repeated_combination
repeated_permutation
compare_by_identity?
19
respond_to_missing?
abort_on_exception=
public_class_method
compare_by_identity
18
undefine_finalizer
instance_variables
abort_on_exception
class_variable_get
class_variable_set
relative_path_from
17
internal_encoding
external_encoding
default_internal=
default_external=
protected_methods
singleton_methods
ascii_compatible?
16
global_variables
executable_real?
initialize_clone
each_with_object # <= Here!
require_relative
private_constant
default_external
included_modules
instance_methods
define_finalizer
default_internal
15
private_methods
fixed_encoding?
class_variables
instance_method
each_with_index
public_constant
garbage_collect
source_location
valid_encoding?
singleton_class
world_writable?
local_variables
world_readable?
method_defined?
14
readable_real?
locale_charmap
const_defined?
collect_concat
initialize_dup
add_trace_func
close_on_exec=
close_on_exec?
named_captures
set_trace_func
write_nonblock
writable_real?
each_codepoint
force_encoding
public_methods
13
const_missing
each_filename
default_proc=
set_backtrace
public_method
read_nonblock
instance_exec
absolute_path
count_objects
instance_eval
12
marshal_load
reverse_each
exclude_end?
instance_of?
make_symlink
set_encoding
block_given?
default_proc
slice_before
marshal_dump
11
rationalize
realdirpath
each_object
expand_path
with_object
</code></pre>
<p>This result shows that methods which has 15+ name length is mostly for reflection or for special purpose. <code>each_with_object</code> is a general purpose method, the name should be shorter.</p>
<p>このリストから分かることは、長さ15を超えるメソッドはその大半がリフレクション用か特殊目的用のものであるという事実です。each_with_objectはより汎用的なメソッドですから、その名前はもっと短くあるべきと考えます。現状の長さは、そのメソッドを無きものにしています。</p>
<p>I propose Enumerable#with for it. a word <code>object</code> in <code>each_with_object</code> is obvious and not necessary to spcify the purpose, because all data in Ruby is <code>object</code>. Also, a word <code>each</code> in <code>each_with_object</code> is not essential, then omittable in view of the fact that it is called to Enumerable object. I think that a word <code>with</code> still works for describing the same of <code>each_with_object</code>.</p>
<p>そこでEnumerable#withを提案します。まず、Rubyで扱われるデータはすべてオブジェクトですから、each_with_objectにおけるobjectは自明であり不要と考えます。次に、Enumerableオブジェクトに対するメソッド呼び出しという点から見て、eachも必須のものとは言えず、削除可能と考えます。そして残ったwithで十分にその目的、つまりEnumerableな要素を任意のオブジェクトと共に操作する、を意図できていると考えます。</p>
<p>Lastly, following is examples with <code>Enumerable#with</code></p>
<p>最後に、<code>Enumerable#with</code>を使った例を示します。</p>
<pre><code>Enumerable.send(:alias_method, :with, :each_with_object)
words.with(Hash.new(0)) { | word, h| h[word] += 1 } # => {"You"=>3, "say"=>10, "Yes"=>1, "I"=>7, "No"=>1, "Stop"=>1, "and"=>2, "Go"=>1, "go"=>2, "Oh"=>1, "no"=>1, "Goodbye"=>2, "Hello"=>2, "hello"=>5, "don"=>2, "t"=>2, "know"=>2, "why"=>2, "you"=>2, "goodbye"=>1}
[*1..10].with(5).map(&:*) # => [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
['ruby', 'python', 'haskell'].with('ist').map(&:+) # => ["rubyist", "pythonist", "haskellist"]
</code></pre>
<p>Thank you for your consideration.</p>
<p>ご検討の程よろしくお願い致します。</p>
<p>=end</p> Ruby master - Feature #5478 (Open): Add syntax to import Set into corehttps://bugs.ruby-lang.org/issues/54782011-10-25T03:46:12Zrkh (Konstantin Haase)me@rkh.im
<p>Set is a central data structure. However, a lot of Ruby developers use arrays for situations where it would be more reasonable to use a set. One reason for that is that it is way easier to use Array than Set at the moment. Another one is that developers are simply not aware that it exists.</p>
<p>I propose to move Set from <code>stdlib</code> to core and possibly add a literal syntax or a method on array for creating a Set.</p>
<p>First class syntax suggestions:</p>
<pre><code><1, 2, 3> # might be tricky to parse
#[1, 2, 3] # would collide with comments
$[1, 2, 3]
${1, 2, 3}
</code></pre>
<p>Method suggestions:</p>
<pre><code>~[1, 2, 3]
+[1, 2, 3]
</code></pre>
<p>Whitespace separated String Sets could look like this:</p>
<pre><code>%w<foo bar blah> # creates an array at the moment
#w[foo bar blah] # would collide with comments
$w[foo bar blah] # would collide with sending :[] to $w
$w{foo bar blah}
~%w[foo bar blah] # not really shorter than using an array with strings
+%w[foo bar balh] # not really shorter than using an array with strings
</code></pre>
<p>Maybe it's ok to not have a whitespace separated syntax. I'm just brainstorming here.</p>
<p>An issue with the method approach is that it would create an Array first to which the message would be sent.</p>
<p>I favor the <code><1, 2, 3></code> syntax, possibly without the ability to create a whitespace separated version.</p>
<p>I'd be willing to work on a patch not only for MRI but also for JRuby and Rubinius if you would consider this to be useful although I would need help with the parser.</p>