Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112013-06-09T22:31:58ZRuby Issue Tracking System
Redmine Ruby master - Feature #8506 (Rejected): Object#iter_for / Object#to_iterhttps://bugs.ruby-lang.org/issues/85062013-06-09T22:31:58Zalindeman (Andy Lindeman)andy@andylindeman.com
<p>=begin<br>
Ruby's (({Enumerator})) and (({#enum_for})) methods are very powerful and I use them very often. However, (({Object#enum_for})) requires a method that yields, usually in some sort of loop.</p>
<p>Many objects in Ruby have methods that iterate to a "next value," but do not yield. For example, (({Fixnum#next.})) There is no way to use (({Fixnum#next})) with (({#enum_for})) directly that I am aware of.</p>
<p>I propose the introduction of (({Object#iter_for})) which--given a method--generates a lazy sequence by continually invoking the method on successive values. I call it (({iter})) or (({iterate})) because it is very similar to clojure's iterate: <a href="http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/iterate" class="external">http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/iterate</a></p>
<p>Proposed API:</p>
<p>0.iter_for(:next).take(5) # => [0, 1, 2, 3, 4]</p>
<p>require 'date'<br>
Date.new(2013, 1, 1).iter_for(:next_month).take(3) # => [Tue, 01 Jan 2013, Fri, 01 Feb 2013, Fri, 01 Mar 2013]</p>
<p>I am especially excited about (({0.iter_for(:next)})) as I find myself using infinite lazy numeric sequences more often lately to solve specific kinds of problems. Right now you are required to write something like: (({Enumerator.new { |y| i = 0; loop { y << i; i += 1 } }})) or (({(0..Float::INFINITY).each})). Neither is especially elegant or happy to the developers' eyes in my opinion.</p>
<p>Thank you all :) Ruby is an amazing tool.<br>
=end</p> Ruby master - Bug #7499 (Closed): public_send can be used to invoke protected methodshttps://bugs.ruby-lang.org/issues/74992012-12-03T06:00:36Zalindeman (Andy Lindeman)andy@andylindeman.com
<p>class Foo<br>
def bar<br>
"wtf?"<br>
end<br>
protected :bar</p>
<p>def invoke_bar<br>
public_send(:bar)<br>
end<br>
end</p>
<p>puts Foo.public_send(:bar) rescue puts "error; this seems normal"</p>
<p>puts Foo.new.invoke_bar</p>
<a name="The-last-statement-outputs-wtf-on"></a>
<h1 >The last statement outputs "wtf?" on:<a href="#The-last-statement-outputs-wtf-on" class="wiki-anchor">¶</a></h1>
<a name="-193p194"></a>
<h1 >* 1.9.3p194<a href="#-193p194" class="wiki-anchor">¶</a></h1>
<a name="-193p327"></a>
<h1 >* 1.9.3p327<a href="#-193p327" class="wiki-anchor">¶</a></h1>
<a name="-ruby-head-2012-12-03"></a>
<h1 >* ruby-head (2012-12-03)<a href="#-ruby-head-2012-12-03" class="wiki-anchor">¶</a></h1>
<a name="The-last-statement-raises-a-NoMethodError-on"></a>
<h1 >The last statement raises a NoMethodError on:<a href="#The-last-statement-raises-a-NoMethodError-on" class="wiki-anchor">¶</a></h1>
<a name="-JRuby-170"></a>
<h1 >* JRuby 1.7.0<a href="#-JRuby-170" class="wiki-anchor">¶</a></h1>
<a name="-rubinius-200dev-2279857e"></a>
<h1 >* rubinius 2.0.0dev 2279857e<a href="#-rubinius-200dev-2279857e" class="wiki-anchor">¶</a></h1>
<h1></h1>
<a name="I-expected-the-NoMethodError-behavior"></a>
<h1 >I /expected/ the NoMethodError behavior<a href="#I-expected-the-NoMethodError-behavior" class="wiki-anchor">¶</a></h1>