|
Prev: Problem with Ruby Multithreading
Next: meaning of %w
From: Srijayanth Sridhar on 1 Jul 2008 04:13 Hello, Is there any design reason for select returning an array and reject returning a hash? Why this disparity? Thank you, Jayanth
From: Dave Bass on 1 Jul 2008 06:39 Srijayanth Sridhar wrote: > Is there any design reason for select returning an array and reject > returning a hash? Why this disparity? In module Enumerable, both select and reject return an array (according to the Pickaxe). -- Posted via http://www.ruby-forum.com/.
From: Srijayanth Sridhar on 1 Jul 2008 06:46 irb(main):001:0> a=Hash.new => {} irb(main):002:0> a[1]=2 => 2 irb(main):003:0> a[2]=2 => 2 irb(main):004:0> a[3]=4 => 4 irb(main):005:0> a.select { |key,value| value > 2 } => [[3, 4]] irb(main):006:0> a.reject { |key,value| value <= 2 } => {3=>4} On Tue, Jul 1, 2008 at 4:09 PM, Dave Bass <davebass(a)musician.org> wrote: > Srijayanth Sridhar wrote: >> Is there any design reason for select returning an array and reject >> returning a hash? Why this disparity? > > In module Enumerable, both select and reject return an array (according > to the Pickaxe). > -- > Posted via http://www.ruby-forum.com/. > >
From: Peña, Botp on 1 Jul 2008 06:58 From: Srijayanth Sridhar [mailto:srijayanth(a)gmail.com] # irb(main):001:0> a=Hash.new # => {} # irb(main):002:0> a[1]=2 # => 2 # irb(main):003:0> a[2]=2 # => 2 # irb(main):004:0> a[3]=4 # => 4 # irb(main):005:0> a.select { |key,value| value > 2 } # => [[3, 4]] # irb(main):006:0> a.reject { |key,value| value <= 2 } # => {3=>4} that will change in newer version of ruby, eg ruby1.9 irb(main):015:0> RUBY_VERSION => "1.9.0" irb(main):016:0> a=Hash.new => {} irb(main):017:0> a[1]=2 => 2 irb(main):018:0> a[2]=2 => 2 irb(main):019:0> a[3]=4 => 4 irb(main):020:0> a.select { |key,value| value > 2 } => {3=>4} irb(main):021:0> a.reject { |key,value| value <= 2 } => {3=>4} kind regards -botp
From: Srijayanth Sridhar on 1 Jul 2008 08:14
> > that will change in newer version of ruby, eg ruby1.9 > > irb(main):015:0> RUBY_VERSION > => "1.9.0" > irb(main):016:0> a=Hash.new > => {} > irb(main):017:0> a[1]=2 > => 2 > irb(main):018:0> a[2]=2 > => 2 > irb(main):019:0> a[3]=4 > => 4 > irb(main):020:0> a.select { |key,value| value > 2 } > => {3=>4} > irb(main):021:0> a.reject { |key,value| value <= 2 } > => {3=>4} > > kind regards -botp > > Thanks. So this is just some sort of artefact/legacy code that never got changed? Jayanth |