list

list(val, depth=0, enc=true)
Class Public methods

### â> definition is moved to TkUtil module def _symbolkey2str(keys)

h = {}
keys.each{|key,value| h[key.to_s] = value}
h

end private :_symbolkey2str module_function :_symbolkey2str

### â> definition is moved to TkUtil module # def hash_kv(keys, enc_mode = nil, conf = [], flat = false) def hash_kv(keys, enc_mode = nil, conf = nil)

# Hash {key=>val, key=>val, ... } or Array [ [key, val], [key, val], ... ]
#     ==> Array ['-key', val, '-key', val, ... ]
dst = []
if keys and keys != None
  keys.each{|k, v|
    #dst.push("-#{k}")
    dst.push('-' + k.to_s)
    if v != None
      # v = _get_eval_string(v, enc_mode) if (enc_mode || flat)
      v = _get_eval_string(v, enc_mode) if enc_mode
      dst.push(v)
    end
  }
end
if conf
  conf + dst
else
  dst
end

end private :hash_kv module_function :hash_kv

### â> definition is moved to TkUtil module def bool(val)

case val
when "1", 1, 'yes', 'true'
  true
else
  false
end

end

def number(val)

case val
when /^-?\d+$/
  val.to_i
when /^-?\d+\.?\d*(e[-+]?\d+)?$/
  val.to_f
else
  fail(ArgumentError, "invalid value for Number:'#{val}'")
end

end def string(val)

if val == "{}"
  ''
elsif val[0] == ?{ && val[-1] == ?}
  val[1..-2]
else
  val
end

end def num_or_str(val)

begin
  number(val)
rescue ArgumentError
  string(val)
end

end

doc_ruby_on_rails
2015-06-04 14:40:21
Comments
Leave a Comment

Please login to continue.