Hello Tobie,

I know $H() is a convenience function, mainly to extend objects to
prototype hashes.
But it accepts any argument, raising the question what sensible return
value either input should yield.

For the input {a:'foo', b:'bar'} the output #<Hash:{a:'foo', b:'bar'}>
is obviously what we want.
For  ['foo', 'bar'] things are not as clear. IMHO, #<Hash:{'0':'foo',
'1':'bar'}> (as returned by prototype 1.4) is perfectly ok. Another
possible result might be #<Hash:{}>, null, 'undefined' or an
exception.

But the actual result is [], that is neither consistent, nor, in any
way I can imagine, useful. $H() should be expected to return Hashes or
undefined, not Arrays.

I can give you an example for usage:
Imagine an arbitrarily deep nested structure of js-objects and arrays
called params.
I could traverse that completely in 1.4, using

    $H(params).each(function(param){
      name     = param[0];
      value     = param[1];
      if (Number(name) != name) {
        // array case, if needed
      }

      if (isObject(paramValue)){
        // recursively call function
      } else {
        // scalar, do something
      }
    });

Now that won't work anymore, I would have to do typechecking first.

I don't say the behaviour in prototype 1.4 is the only way to go, for
me it was perfect.
But the newer behaviour is definitely worth reconsidering.

Kind regards,
Alex


On Feb 3, 11:15 am, "tobie" <[EMAIL PROTECTED]> wrote:
> Hi Alexander,
>
> Sorry to hear that you are encountering issues with your update to
> 1.5.
>
> Apart from the fact that it breaks some of your code - I know how
> painful that is - could you maybe give a bit more info on when such
> behavior is useful ?
>
> Enumerable is mixed it to Array just like its mixed in to Hash ($H).
> So I'm not sure I understand in which case you'd need to use
> $H([...]).
>
> Regards,
>
> Tobie


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to