[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: object loops and what they return

Eric Mahurin

5/11/2005 11:01:00 PM

> > Consider these loops:
> >
> > <object>.<loop-method> { <code> }
> >
> > where loop method is each, each_with_index, upto, downto,
> step,
> > and probably others.
> >
> > Although it is not documented, all of these look to return
> the
> > original object (collection or int).
>
> I think the return values are documented in ri for all of
> these.

Enumerable says nothing about the return value or each.
Array.each says it returns an Array, but not what's in that
Array. Before testing, I was thinking it might be the same as
map/collect. The integer loops also say they return an
integer, but not what it is.

> > With "each" returning nil, you can also see that many of
> the
> > derived loops in Enumerable become trival almost to where
> you
> > don't need them.
>
> On the other hand, if you were to do this (looking for nil):
>
> obj = array.each {|e| break(e) if e.nil? }
>
> and each returned nil, you wouldn't know whether you'd
> succeeded or
> not.

Then you do it another way. Differentiating between the
element nil in a collection and nil meaning nothing is a common
problem, I think. You have the same problem using find:

obj = array.find{|e| not e.kind_of?Integer }

If you were looking for the first non-integer in array and it
happened to be nil, you couldn't tell whether nil was that
object or there were no non-integers.

> The various find and include? and any? and index methods are
> probably
> your best bet for this kind of operation.

In the particular code I was looking at, none of them worked (I
think I looked at all of them). I needed a different compare
(equal?) and in one case I wanted to go in reverse order.




Discover Yahoo!
Use Yahoo! to plan a weekend, have fun online and more. Check it out!
http://discover....


6 Answers

dblack

5/11/2005 11:19:00 PM

0

Gavin Kistner

5/11/2005 11:30:00 PM

0

Eric Mahurin wrote:
> Enumerable says nothing about the return value or each.
> Array.each says it returns an Array, but not what's in that
> Array. Before testing, I was thinking it might be the same as
> map/collect. The integer loops also say they return an
> integer, but not what it is.

You seem to be not so much interested in whether or not people use this
feature, as instead convincing them that they shouldn't use them,
because you'd like to see the feature go away.

(Which is fine...expressing one's opinions and attempting to sway
others' it one fine use of the mailing list :)

However, I fail to see as valid the argument that we should not be
using a feature just because the documentation is incomplete. Instead,
the documentation should be fixed.

There may certainly to be some side-effects of idiosyncracies of the
language implementation upon which one should not rely, but that
specific self return value of certain methods smells far more like an
intentional feature than a bug.


Your argument that they should return nil for consistency certainly has
some merit. I counter-argue that if you're always going to return the
same value from a method, returning the receiver is usually preferable
over returning nil.

I vote: don't take away my feature just because you don't like it, and
don't like that I use chaining across blocks which (to some) looks
ugly. :)

Rick Rothstein \(MVP - VB\)

6/18/2008 5:44:00 PM

0

Merged cells? Bingo! I don't work with merged cells myself, but the word is
they are the cause of untold problems. Since the formula I posted works for
me using no merged cells, and not for you with your merged cells, I'd have
to say that is what is causing the formula not to work.

Rick


"frustratedwthis" <frustratedwthis@discussions.microsoft.com> wrote in
message news:6BAE911A-2564-4491-92B5-2FBD4AF78A55@microsoft.com...
>I tried that, however, it gives me the validation error even if there is
>text
> in the cell. Another thing that might be causing the problem is, the
> cells
> are merged. (A12:I13)
> I put the validation code in cells A17:20. I am not sure what it is I am
> doing wrong
> :(
> Thanks
>
>
> "Rick Rothstein (MVP - VB)" wrote:
>
>> You don't put the validation on the "description cell" itself, you put it
>> on
>> the cells below it that you don't want to allow an entry in if the
>> "description cell" is blank. For example, if B3 is the address of your
>> "description cell", then select the cells below it, starting with B4 (so
>> that B4 remains the active cell) and put this Custom formula in the
>> Data/Validation for that selection...
>>
>> =LEN(OFFSET(B$4,-1,0))>0
>>
>> Just make sure you replace my example B$4 address with the address
>> (absolute
>> row) for the active cell in your selection.
>>
>> Rick
>>
>>
>> "frustratedwthis" <frustratedwthis@discussions.microsoft.com> wrote in
>> message news:AC4FF9AF-B0FF-4486-A6D1-5CB71DA93910@microsoft.com...
>> >I have read through MANY of the posts on here and haven't seemed to find
>> >an
>> > answer(and if I overlooked it, sorry!)
>> > I am trying to put data validation on a "description" cell. I would
>> > like
>> > a
>> > validation box to pop up if the user skips the description box and
>> > fills
>> > out
>> > the information below it. Can this be done? I have tried ISBLANK, and
>> > a
>> > few
>> > "" formulas and am having NO luck.
>> > Thanks in advance :)
>> >
>>
>>

frustratedwthis

6/18/2008 8:18:00 PM

0

I unmerged my cells and still a no go. I have no idea what I am doing wrong.
Thank you for all your help!

"Rick Rothstein (MVP - VB)" wrote:

> Merged cells? Bingo! I don't work with merged cells myself, but the word is
> they are the cause of untold problems. Since the formula I posted works for
> me using no merged cells, and not for you with your merged cells, I'd have
> to say that is what is causing the formula not to work.
>
> Rick
>
>
> "frustratedwthis" <frustratedwthis@discussions.microsoft.com> wrote in
> message news:6BAE911A-2564-4491-92B5-2FBD4AF78A55@microsoft.com...
> >I tried that, however, it gives me the validation error even if there is
> >text
> > in the cell. Another thing that might be causing the problem is, the
> > cells
> > are merged. (A12:I13)
> > I put the validation code in cells A17:20. I am not sure what it is I am
> > doing wrong
> > :(
> > Thanks
> >
> >
> > "Rick Rothstein (MVP - VB)" wrote:
> >
> >> You don't put the validation on the "description cell" itself, you put it
> >> on
> >> the cells below it that you don't want to allow an entry in if the
> >> "description cell" is blank. For example, if B3 is the address of your
> >> "description cell", then select the cells below it, starting with B4 (so
> >> that B4 remains the active cell) and put this Custom formula in the
> >> Data/Validation for that selection...
> >>
> >> =LEN(OFFSET(B$4,-1,0))>0
> >>
> >> Just make sure you replace my example B$4 address with the address
> >> (absolute
> >> row) for the active cell in your selection.
> >>
> >> Rick
> >>
> >>
> >> "frustratedwthis" <frustratedwthis@discussions.microsoft.com> wrote in
> >> message news:AC4FF9AF-B0FF-4486-A6D1-5CB71DA93910@microsoft.com...
> >> >I have read through MANY of the posts on here and haven't seemed to find
> >> >an
> >> > answer(and if I overlooked it, sorry!)
> >> > I am trying to put data validation on a "description" cell. I would
> >> > like
> >> > a
> >> > validation box to pop up if the user skips the description box and
> >> > fills
> >> > out
> >> > the information below it. Can this be done? I have tried ISBLANK, and
> >> > a
> >> > few
> >> > "" formulas and am having NO luck.
> >> > Thanks in advance :)
> >> >
> >>
> >>
>
>

Rick Rothstein \(MVP - VB\)

6/18/2008 8:26:00 PM

0

I'm not sure what cells you had merged together nor what cells are now in
use after you unmerged them. What is your layout now; that is, where is your
"description cell" located? Also, if you set up the formula while your cells
were merged, I'm guess it got screwed up when you unmerged the cells, so you
may have to re-select the range of cells you want to have the validation and
re-apply the validation formula.

Rick


"frustratedwthis" <frustratedwthis@discussions.microsoft.com> wrote in
message news:B8100280-F78B-4D97-82EA-F69752B897E0@microsoft.com...
>I unmerged my cells and still a no go. I have no idea what I am doing
>wrong.
> Thank you for all your help!
>
> "Rick Rothstein (MVP - VB)" wrote:
>
>> Merged cells? Bingo! I don't work with merged cells myself, but the word
>> is
>> they are the cause of untold problems. Since the formula I posted works
>> for
>> me using no merged cells, and not for you with your merged cells, I'd
>> have
>> to say that is what is causing the formula not to work.
>>
>> Rick
>>
>>
>> "frustratedwthis" <frustratedwthis@discussions.microsoft.com> wrote in
>> message news:6BAE911A-2564-4491-92B5-2FBD4AF78A55@microsoft.com...
>> >I tried that, however, it gives me the validation error even if there is
>> >text
>> > in the cell. Another thing that might be causing the problem is, the
>> > cells
>> > are merged. (A12:I13)
>> > I put the validation code in cells A17:20. I am not sure what it is I
>> > am
>> > doing wrong
>> > :(
>> > Thanks
>> >
>> >
>> > "Rick Rothstein (MVP - VB)" wrote:
>> >
>> >> You don't put the validation on the "description cell" itself, you put
>> >> it
>> >> on
>> >> the cells below it that you don't want to allow an entry in if the
>> >> "description cell" is blank. For example, if B3 is the address of your
>> >> "description cell", then select the cells below it, starting with B4
>> >> (so
>> >> that B4 remains the active cell) and put this Custom formula in the
>> >> Data/Validation for that selection...
>> >>
>> >> =LEN(OFFSET(B$4,-1,0))>0
>> >>
>> >> Just make sure you replace my example B$4 address with the address
>> >> (absolute
>> >> row) for the active cell in your selection.
>> >>
>> >> Rick
>> >>
>> >>
>> >> "frustratedwthis" <frustratedwthis@discussions.microsoft.com> wrote in
>> >> message news:AC4FF9AF-B0FF-4486-A6D1-5CB71DA93910@microsoft.com...
>> >> >I have read through MANY of the posts on here and haven't seemed to
>> >> >find
>> >> >an
>> >> > answer(and if I overlooked it, sorry!)
>> >> > I am trying to put data validation on a "description" cell. I would
>> >> > like
>> >> > a
>> >> > validation box to pop up if the user skips the description box and
>> >> > fills
>> >> > out
>> >> > the information below it. Can this be done? I have tried ISBLANK,
>> >> > and
>> >> > a
>> >> > few
>> >> > "" formulas and am having NO luck.
>> >> > Thanks in advance :)
>> >> >
>> >>
>> >>
>>
>>

frustratedwthis

6/19/2008 6:48:00 PM

0

Cells A12:I13 are merged so that the user can key in a description using text
and #'s if necessary. Without the cells being merged, the description would
be in A12.
I am putting the data validation formula in cells A17:A20. In these cells,
you put an "X" to choose a corresponding goal. I would like to set it up
where they can't choose a corresponding goal without a description.
Again, thank you for your help :)

"Rick Rothstein (MVP - VB)" wrote:

> I'm not sure what cells you had merged together nor what cells are now in
> use after you unmerged them. What is your layout now; that is, where is your
> "description cell" located? Also, if you set up the formula while your cells
> were merged, I'm guess it got screwed up when you unmerged the cells, so you
> may have to re-select the range of cells you want to have the validation and
> re-apply the validation formula.
>
> Rick
>
>
> "frustratedwthis" <frustratedwthis@discussions.microsoft.com> wrote in
> message news:B8100280-F78B-4D97-82EA-F69752B897E0@microsoft.com...
> >I unmerged my cells and still a no go. I have no idea what I am doing
> >wrong.
> > Thank you for all your help!
> >
> > "Rick Rothstein (MVP - VB)" wrote:
> >
> >> Merged cells? Bingo! I don't work with merged cells myself, but the word
> >> is
> >> they are the cause of untold problems. Since the formula I posted works
> >> for
> >> me using no merged cells, and not for you with your merged cells, I'd
> >> have
> >> to say that is what is causing the formula not to work.
> >>
> >> Rick
> >>
> >>
> >> "frustratedwthis" <frustratedwthis@discussions.microsoft.com> wrote in
> >> message news:6BAE911A-2564-4491-92B5-2FBD4AF78A55@microsoft.com...
> >> >I tried that, however, it gives me the validation error even if there is
> >> >text
> >> > in the cell. Another thing that might be causing the problem is, the
> >> > cells
> >> > are merged. (A12:I13)
> >> > I put the validation code in cells A17:20. I am not sure what it is I
> >> > am
> >> > doing wrong
> >> > :(
> >> > Thanks
> >> >
> >> >
> >> > "Rick Rothstein (MVP - VB)" wrote:
> >> >
> >> >> You don't put the validation on the "description cell" itself, you put
> >> >> it
> >> >> on
> >> >> the cells below it that you don't want to allow an entry in if the
> >> >> "description cell" is blank. For example, if B3 is the address of your
> >> >> "description cell", then select the cells below it, starting with B4
> >> >> (so
> >> >> that B4 remains the active cell) and put this Custom formula in the
> >> >> Data/Validation for that selection...
> >> >>
> >> >> =LEN(OFFSET(B$4,-1,0))>0
> >> >>
> >> >> Just make sure you replace my example B$4 address with the address
> >> >> (absolute
> >> >> row) for the active cell in your selection.
> >> >>
> >> >> Rick
> >> >>
> >> >>
> >> >> "frustratedwthis" <frustratedwthis@discussions.microsoft.com> wrote in
> >> >> message news:AC4FF9AF-B0FF-4486-A6D1-5CB71DA93910@microsoft.com...
> >> >> >I have read through MANY of the posts on here and haven't seemed to
> >> >> >find
> >> >> >an
> >> >> > answer(and if I overlooked it, sorry!)
> >> >> > I am trying to put data validation on a "description" cell. I would
> >> >> > like
> >> >> > a
> >> >> > validation box to pop up if the user skips the description box and
> >> >> > fills
> >> >> > out
> >> >> > the information below it. Can this be done? I have tried ISBLANK,
> >> >> > and
> >> >> > a
> >> >> > few
> >> >> > "" formulas and am having NO luck.
> >> >> > Thanks in advance :)
> >> >> >
> >> >>
> >> >>
> >>
> >>
>
>