Method: Array#join
- Defined in:
- lib/webget_ruby_ramp/array.rb
#join(*fixes) ⇒ Object
Concatenate the items into a string by join.
Typical Array#join with infix
list=['a','b','c']
list.join("*") => "a*b*c"
Improved join with infix, prefix, suffix
list=['a','b','c']
list.join("*","[","]") => "[a]*[b]*[c]"
Improved join with just prefix and suffix
list=['a','b','c']
list.join("[","]") => "[a][b][c]"
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/webget_ruby_ramp/array.rb', line 29 def join(*fixes) if fixes.is_a?(String) then return self.ruby_join(fixes) end case fixes.size when 0 return self.ruby_join() when 1 return self.ruby_join(fixes[0]) when 2 prefix=fixes[0].to_s suffix=fixes[1].to_s return self.map{|item| prefix + item.to_s + suffix}.ruby_join() when 3 infix =fixes[0].to_s prefix=fixes[1].to_s suffix=fixes[2].to_s return self.map{|item| prefix + item.to_s + suffix}.ruby_join(infix) else raise ArgumentError, "join() takes 0-3 arguments; you gave #{fixes.size}]" end end |