Sha256: 7cc3cf9cb8b9763fc43a0990313dbf11c42d18768d4a184517a2a80e13e2f81a
Contents?: true
Size: 780 Bytes
Versions: 74
Compression:
Stored size: 780 Bytes
Contents
# encoding: utf-8 module EvalHelper # create each with index do single line code, for eval # # ==== Examples # # class EvalHelperEachWithIndexDoTest # include EvalHelper # # def hoge(hash) # each_with_index_do_code(hash[:target], hash[:proc]) # end # end # # hash = { # target: '[:a, :b]', # proc: "puts \"\#{i}:\#{v}1\"\nputs \"\#{i}:\#{v}2\"\n", # } # EvalHelperEachWithIndexDoTest.new.hoge(hash) # => return "[:a, :b].each_with_index do |v, i|\n puts \"\#{i}:\#{v}1\"\n puts \"\#{i}:\#{v}2\"\nend" # def each_with_index_do_code(target, proc) indented = proc.split("\n").reduce([]) { |ret, v|ret << " #{v}" ; ret }.join("\n") "#{target}.each_with_index do |v, i|\n#{indented}\nend" end end
Version data entries
74 entries across 74 versions & 1 rubygems