Module: Paramesan::ClassMethods
- Included in:
- Paramesan
- Defined in:
- lib/paramesan.rb
Instance Method Summary collapse
Instance Method Details
#param_test(paramlist, &blk) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/paramesan.rb', line 8 def param_test paramlist, &blk count = paramlist.count paramlist.each_with_index do |params, idx| name = param_test_name params, idx, count mname = name.to_sym i = 0 while instance_methods.include? mname.to_sym i += 1 mname = name + "_#{i}" end define_method mname do instance_exec(params, &blk) end end end |
#param_test_name(params, idx, count) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/paramesan.rb', line 26 def param_test_name params, idx, count name = "test_" + idx.to_s + "_of_" + count.to_s + "__" if params.kind_of?(Enumerable) nonword = Regexp.new '[^\w]+' elements = params.collect { |param| param.to_s.gsub nonword, '_' } name << elements.join('_') else name << params.to_s end end |