[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [QUIZ] metakoans.rb (#67

Patrick Hurley

2/17/2006 10:23:00 PM

On 2/17/06, Ruby Quiz <james@grayproductions.net> wrote:
> #
> # 'attribute' must provide a method for providing a default value as hash
> #

> #
> # 'attribute' must provide a method for providing a default value as block
> # which is evaluated at instance level
> #

<pedantic>
What if they provide both?
</pedantic>

pth


15 Answers

Ara.T.Howard

2/17/2006 10:31:00 PM

0

Patrick Hurley

2/17/2006 10:40:00 PM

0

On 2/17/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> On Sat, 18 Feb 2006, Patrick Hurley wrote:
>
> > On 2/17/06, Ruby Quiz <james@grayproductions.net> wrote:
> >> #
> >> # 'attribute' must provide a method for providing a default value as hash
> >> #
> >
> >> #
> >> # 'attribute' must provide a method for providing a default value as block
> >> # which is evaluated at instance level
> >> #
> >
> > <pedantic>
> > What if they provide both?
> > </pedantic>
>
>
> i generally make a block the winner because it's bigger visually and harder to
> type - ergo one generally meant it if one typed it. whereas a hash is easy to
> accidentally pass using
>
> attribute(*args){ Time::now }
> ^
> ^
> hash in here
>
> suppose you could throw an error too - not my style - but it makes sense.
>
> cheers.
>
> -a
>
> --
> judge your success by what you had to give up in order to get it.
> - h.h. the 14th dali lama
>
>

Thanks ok last question (probalby), if remove_instance_variable is
called, and the attribute is subsequently accessed is it reset to the
default value?

Thanks again for a good quiz
pth


Ara.T.Howard

2/17/2006 10:50:00 PM

0

MenTaLguY

2/18/2006 12:07:00 AM

0

Quoting ara.t.howard@noaa.gov:

> On Sat, 18 Feb 2006, Patrick Hurley wrote:
>
> > Thanks ok last question (probalby), if remove_instance_variable
> > is called, and the attribute is subsequently accessed is it
> > reset to the default value?
>
> good question. my version does not - the default is set once
> only. i would think re-setting an @var when
> remove_instance_variable has been called would be suprising
> behaviour - but it's up to you.

Depends. If you think of it in terms of the default value being
shadowed by @var if it exists, returning to the default value after
a remove_instance_variable would seem reasonable.

This indirectly brings to mind another question, though -- when and
how often is the block supposed to be called, if given? Once?
Per-class? Per-object? Per-get?

-mental


Jacob Fugal

2/18/2006 12:26:00 AM

0

On 2/17/06, Wilson Bilkovich <wilsonb@gmail.com> wrote:
> Awesome quiz. For a while there, I didn't think I was going to
> succeed. My favorite part is how removing code often let me pass more
> tests. Very zen.

Amen, I ran into that too :)

Jacob Fugal

(Final result, 42 lines, with whitespace)


Wilson Bilkovich

2/18/2006 12:30:00 AM

0

On 2/17/06, Jacob Fugal <lukfugl@gmail.com> wrote:
> On 2/17/06, Wilson Bilkovich <wilsonb@gmail.com> wrote:
> > Awesome quiz. For a while there, I didn't think I was going to
> > succeed. My favorite part is how removing code often let me pass more
> > tests. Very zen.
>
> Amen, I ran into that too :)
>
> Jacob Fugal
>
> (Final result, 42 lines, with whitespace)
>

Just got mine down to 30. I'm really looking forward to seeing the
shortest solution, because I have a feeling it's going to humiliate
that.


MenTaLguY

2/18/2006 1:21:00 AM

0

Quoting Wilson Bilkovich <wilsonb@gmail.com>:

> Just got mine down to 30. I'm really looking forward to seeing
> the shortest solution, because I have a feeling it's going to
> humiliate that.

23, with copious whitespace.

It's like Taoist golf. Strive without striving.

-mental


Ara.T.Howard

2/18/2006 1:38:00 AM

0

Ara.T.Howard

2/18/2006 1:38:00 AM

0

MenTaLguY

2/18/2006 1:41:00 AM

0

Quoting ara.t.howard@noaa.gov:

> per-object - where object may be a class (singleton method).

Hmm, would semantics like Hash's default block be acceptable?

-mental