lib/open_classes/array.rb in tbpgr_utils-0.0.17 vs lib/open_classes/array.rb in tbpgr_utils-0.0.18
- old
+ new
@@ -129,13 +129,21 @@
memo = instance_eval "yield(memo, #{eval_each_str})"
end
memo
end
- alias_methods [:together_collect, :tmap, :tcollect], :together_map
- alias_methods [:together_find_all, :tselect, :tfindall], :together_select
- alias_methods [:together_inject, :treduce, :tinject], :together_reduce
+ # Arrays bulk concat.
+ #
+ # alpha = %w{one two three}
+ # numbers = %w{1 2 3}
+ # [alpha, numbers].together do |first, second|
+ # print "#{first}:#{second}\n" # => output one:1, two:2, three:3
+ # end
+ def together_concat(other)
+ if_not_contain_array_rails_type_error
+ each { |list|list.concat other }
+ end
private
def if_not_contain_array_rails_type_error
each { |f|fail TypeError, "you have to use [Array1, Array2, ...] | #{f.class} is invalid" unless f.class == Array }
@@ -179,6 +187,11 @@
end
def together_return_multi?(list)
(list.class == Array && list.size == size).to_bool
end
+
+ alias_method :tconcat, :together_concat
+ alias_methods [:together_collect, :tmap, :tcollect], :together_map
+ alias_methods [:together_find_all, :tselect, :tfindall], :together_select
+ alias_methods [:together_inject, :treduce, :tinject], :together_reduce
end