On Thu, Jan 3, 2013 at 9:37 PM, Salvatore nashcrash
<[email protected]> wrote:
> Hi.
> I'm a newby in this Forum and in Ruby, but I want give my contribution.
>
> class Array
>   alias oldJoin join
>   def join(sep='')
>     res=self
>     res=self.map {|el| yield el} if block_given?
>     res.oldJoin(sep)
>   end
> end
>
> What you things about-it?

I am thinking that this version is in no way better than using #map
and #join explicitly.  If you want to make this more efficient, you'd
at least have to do something like this

class Array
  def join(sep = '', &b)
    b ||= lambda {|x| x}
    s = nil

    each do |e|
      if s
        s << sep
      else
        s = ''
      end << (b[e].to_s)
    end

    s
  end
end

I am not sure though that this is such a great idea because you can
usually do this via #inject.

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google 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 https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to