On Feb 3, 7:00 pm, "Mislav" <[EMAIL PROTECTED]> wrote:
> > Can somebody explain if this is just an error or wanted behaviour. We
> > are facing big problems because of that.
>
> Prototype (in some ways) follows conventions of the Ruby language
> where Array and Hash aren't interchangeable. This is unlike PHP where
> arrays are used as both.
>
> In other words, your data should be either an array or hash.
That goes without mentioning.
The question I wanted to raise was, if $H() shouldn't be expected to
reliably return Hash objects or undefined/exception.
If the answer is Hashes (as it was), it would still be have to figured
out, how to do that for arbitrary input.
E.g.
$H(['a','b']) => #<Hash{'0':'a', '1':'b'};
$H(1) => #<Hash{'0':1}, or the like
Kind regards
Alex
> We will still consider your issue, but in the meantime use the
> following function in your scripts to override the original:
>
> function $H(object) {
> if (object) {
> switch (object.constructor) {
> case Hash: return object;
> case Array:
> var h = new Hash;
> object.each(function(value, i){ h[i] = value });
> return h;
> }
> }
> return new Hash(object);
>
> };
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---