The contract states that Enumerable#reject "Returns all the elements
for which the iterator returned false". It's entirely intuitive that
it will return the same data type as the object it was called on.
Otherwise Hash#reject() is practically useless.

The only part of the documentation that is wrong is the assumption
that it will always return an Array. Perhaps that was an oversight
when Hash was left out as a subclass of Enumerable in the
documentation.

Ruby fixed their documentation:
Hash#reject: http://www.ruby-doc.org/core/classes/Hash.html#M002901
Enumerable#reject: http://www.ruby-doc.org/core/classes/Enumerable.html#M003157

On Feb 3, 1:56 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Kangax,
>
> > Didn't we establish that this is a bug? ; )
>
> Not as far as I'm concerned it isn't.  It returns what its documented
> contract says it returns.  The only error IMHO is in the
> interpretation that it would do something other than what the
> documentation says it will do.  You're not suggesting it should break
> the Enumerable contract, are you?
>
> -- T.J. ;-)
>
> On Feb 3, 7:03 pm, kangax <kan...@gmail.com> wrote:
>
> > On Feb 3, 1:54 pm, Brad <bradavo...@gmail.com> wrote:
>
> > > TJ, thanks for correcting the docs. I hadn't noticed that error
> > > either.
>
> > > Are you suggesting that there no intersection of Prototype and Ruby
> > > communities? I only know of Prototype because of Ruby on Rails.
>
> > > Let's take Hash#reject() as an example. Let's say I'm moving server-
> > > side Ruby code to my Prototype-enhanced client-side.
>
> > > Ruby code:
> > > { "a" => 100, "b" => 200, "c" => 300 }.reject {|key, value| key ==
> > > "b" }
> > > => {"a"=>100, "c"=>300}
>
> > > Translated to Javascript:
> > > $H({ "a": 100, "b": 200, "c": 300 }).reject(function(i) { return i.key
> > > == "b" })
> > > => [["a", 100], ["c", 300]]
>
> > > Prototype returns an array? What good is an array if I started with a
> > > hash? It is intuitive that a reject() method returns a subset of the
> > > original data structure and not convert it to an entirely different
> > > one.
>
> > Didn't we establish that this is a bug? ; )
>
> > --
> > kangax
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to