Sha256: 3c5d603fb649a6c50fcdfd170bedee6b141be21320e62ef36c149d62121504f8
Contents?: true
Size: 1.19 KB
Versions: 89
Compression:
Stored size: 1.19 KB
Contents
# encoding: utf-8 module EvalHelper # create set variables logic strings, for eval # # ==== Examples # # set string variables case # # class EvalHelperSetVariablesTest # include EvalHelper # # def hoge(variables) # set_variables_code(variables) # end # end # # variables = [ # { # name: 'name1', # value: '"value1"', # }, # { # name: 'name2', # value: '"value2"', # }, # ] # EvalHelperSetVariablesTest.new.hoge(variables) # # return # # name1 = "value1" # name2 = "value2" # def set_variables_code(variables) fail TypeError, "invalid type #{variables.class}. you have to use Array" unless variables.is_a? Array variables.reduce([]) do |ret, variable| fail TypeError, "invalid type #{variable.class}. you have to use Hash" unless variable.is_a? Hash fail TypeError, 'invalid hash. you have to set Hash[:name]' if variable[:name].nil? fail TypeError, 'invalid hash. you have to set Hash[:value]' if variable[:value].nil? ret << "#{variable[:name]} = #{variable[:value]}" ret end.join("\n") end end
Version data entries
89 entries across 89 versions & 1 rubygems