[#2367] Standard libraries — Dave Thomas <dave@...>

From ruby-dev summary:

60 messages 2004/02/11

[#2397] PATCH: deprecate cgi-lib, getopts, importenv, parsearg from standard library — Gavin Sinclair <gsinclair@...>

Index: cgi-lib.rb

15 messages 2004/02/12

[#2465] PATCH: OpenStruct#initialize to yield self — Gavin Sinclair <gsinclair@...>

This is a common approach I use to object initialization; I don't know

24 messages 2004/02/19

Re: Change to #new (was OpenStruct#initialize to yield self)

From: Austin Ziegler <austin@...>
Date: 2004-02-20 20:19:29 UTC
List: ruby-core #2479
On Fri, 20 Feb 2004 21:50:09 +0900, Dave Thomas wrote:
> On Feb 19, 2004, at 23:59, Austin Ziegler wrote:
>> Would the presence of &blk immediately make super pretend to be super
>> {}?
> It _could_.... but whether it should is another matter :)

I think that what I'm uncomfortable with is the possible "magic" involved 
here. I actually agree with the proposal and think that it's a good idea in 
general; I'm just not comfortable with how we'd transition *to* this.

Then again, I just tried this in 1.8.0 (I'm too lazy to upgrade to 1.8.1 
right at the moment :)) and got:

irb(main):001:0> class Foo
irb(main):002:1>   def baz
irb(main):003:2>     yield "Foo#baz" if block_given?
irb(main):004:2>   end
irb(main):005:1> end
=> nil
irb(main):006:0> class Bar < Foo
irb(main):007:1>   def baz
irb(main):008:2>     yield "Bar#baz" if block_given?
irb(main):009:2>     super
irb(main):010:2>   end
irb(main):011:1> end
=> nil
irb(main):012:0> b = Bar.new
=> #<Bar:0x2803f00>
irb(main):013:0> b.baz { |a| puts a }
Bar#baz
Foo#baz
=> nil

So if we're yielding *and* calling the super of the method, we have to call 
super {} unless we want the super to yield as well.

-austin
--
austin ziegler    * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.02.20
                                         * 15.11.47




In This Thread