Ara.T.Howard wrote:

<snip/>

>    harp:~ > cat a.rb
>    class CD
>      ATTRIBUTES = %w(
>        size
>        cusip
>      )
>      ATTRIBUTES.each{|a| attr_accessor a}
>      def initialize hash
>        hash.each{|k,v| send "#{ k }=", v}
>      end
>      def inspect
>        'cd(' << ATTRIBUTES.map{|k| [k,send(k)].join('=')}.join(', ')
>      << ')' end
>    end
> 
>    class CDList < ::Array
>      def sorted_by *keys
>        block = lambda{|cd| keys.flatten.map{|k| cd.send k}}
>        sort_by &block
>      end
>    end

Why not directly use the block?  I think it's a tad more efficient:

def sort_by(*keys)
  sort_by {|x| keys.map {|k| x.send k}}
end

> 
>    class Fixnum
>      def of
>        ret = []; times{|i| ret << yield(i) }; ret
>      end
>    end

Alternative

def of(&b) (0...self).map(&b) end

But what do you need that for?  I couldn't find it...

<snip/>

Kind regards

    robert