hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

(String < Enumerable).nil? #

by why in inspect

So, it sounds like the 1.9 series will remove Enumerable from String’s ancestry, in favor of String#lines. All string iteration casts to an Array. Maybe I’m getting my hopes up, but all these string changes seem like portents of Unicode Times.

 >> str = "pony\nwagon\nstungun\n" 
 => "pony\nwagon\nstungun\n" 
 >> str.max
 NoMethodError: undefined method `max' for "pony\nwagon\nstungun\n":String
        from (irb):2:in `Kernel#binding'
 >> str.lines.max
 => "wagon\n" 

Makes sense. Anyone else mourning the impotent string splat?

 >> utilities = *str
 => ["pony\nwagon\nstungun\n"]

Like a little rotary saw whose tooth got stuck. (from matz and patch.)

said on 29 Sep 2006 at 11:23

So does "one\ntwo".to_a still return ["one\n", "two"], or did String’s to_a come from Enumerable?

said on 29 Sep 2006 at 12:03

Removing Enumerable makes sense – there were only two methods most people cared about anyway – ‘to_a’ and ‘each’. The latter is far more important from an interface perspective IMO .

I’m curious how both of these are handled.

said on 30 Sep 2006 at 08:16

Hooray!

said on 30 Sep 2006 at 21:15

Didn’t you mean idempotent string splat?

said on 01 Oct 2006 at 15:01

impotent seems appropriate!

said on 02 Oct 2006 at 03:10

Brilliant! One of the early things that bit me in Ruby was the fact that Strings broke the def foo(arg); case arg; when Enumerable; arg.each {|i| foo(i)} ... pattern.

said on 02 Oct 2006 at 06:16

Hmm. Well, at least it’ll stop me expecting ‘string’.each to yield each character (well, modulo Unicode support) in turn…

11 Jul 2010 at 21:15

* do fancy stuff in your comment.

PREVIEW PANE