_curr_cmd_id

_curr_cmd_id()
Class Public methods

### â> definition is moved to TkUtil module def _get_eval_string(str, enc_mode = nil)

return nil if str == None
if str.kind_of?(TkObject)
  str = str.path
elsif str.kind_of?(String)
  str = _toUTF8(str) if enc_mode
elsif str.kind_of?(Symbol)
  str = str.id2name
  str = _toUTF8(str) if enc_mode
elsif str.kind_of?(Hash)
  str = hash_kv(str, enc_mode).join(" ")
elsif str.kind_of?(Array)
  str = array2tk_list(str)
  str = _toUTF8(str) if enc_mode
elsif str.kind_of?(Proc)
  str = install_cmd(str)
elsif str == nil
  str = ""
elsif str == false
  str = "0"
elsif str == true
  str = "1"
elsif (str.respond_to?(:to_eval))
  str = str.to_eval()
  str = _toUTF8(str) if enc_mode
else
  str = str.to_s() || ''
  unless str.kind_of? String
    fail RuntimeError, "fail to convert the object to a string"
  end
  str = _toUTF8(str) if enc_mode
end
return str

end

def _get_eval_string(obj, enc_mode = nil)

case obj
when Numeric
  obj.to_s
when String
  (enc_mode)? _toUTF8(obj): obj
when Symbol
  (enc_mode)? _toUTF8(obj.id2name): obj.id2name
when TkObject
  obj.path
when Hash
  hash_kv(obj, enc_mode).join(' ')
when Array
  (enc_mode)? _toUTF8(array2tk_list(obj)): array2tk_list(obj)
when Proc, Method, TkCallbackEntry
  install_cmd(obj)
when false
  '0'
when true
  '1'
when nil
  ''
when None
  nil
else
  if (obj.respond_to?(:to_eval))
    (enc_mode)? _toUTF8(obj.to_eval): obj.to_eval
  else
    begin
      obj = obj.to_s || ''
    rescue
      fail RuntimeError, "fail to convert object '#{obj}' to string"
    end
    (enc_mode)? _toUTF8(obj): obj
  end
end

end private :_get_eval_string module_function :_get_eval_string

### â> definition is moved to TkUtil module def _get_eval_enc_str(obj)

return obj if obj == None
_get_eval_string(obj, true)

end private :_get_eval_enc_str module_function :_get_eval_enc_str

### â> obsolete def ruby2tcl(v, enc_mode = nil)

if v.kind_of?(Hash)
  v = hash_kv(v)
  v.flatten!
  v.collect{|e|ruby2tcl(e, enc_mode)}
else
  _get_eval_string(v, enc_mode)
end

end private :ruby2tcl

### â> definition is moved to TkUtil module def _conv_args(args, enc_mode, *src_args)

conv_args = []
src_args.each{|arg|
  conv_args << _get_eval_string(arg, enc_mode) unless arg == None
  # if arg.kind_of?(Hash)
  # arg.each{|k, v|
  #   args << '-' + k.to_s
  #   args << _get_eval_string(v, enc_mode)
  # }
  # elsif arg != None
  #   args << _get_eval_string(arg, enc_mode)
  # end
}
args + conv_args

end private :_conv_args

doc_ruby_on_rails
2015-06-04 14:08:58
Comments
Leave a Comment

Please login to continue.