Module: Tk::CoreExtensions::Array

Defined in:
lib/ffi-tk/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#tcl_options_to_hash(hints = {}) ⇒ Object

try to convert to a Hash. it may return an Array if this contains none.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ffi-tk/core_extensions.rb', line 19

def tcl_options_to_hash(hints = {})
  if first.respond_to?(:to_ary)
    hash = {}

    each do |key, _, _, _, value|
      next if !value || (value.respond_to?(:empty?) && value.empty?)
      key = key.sub(/^-/, '').to_sym

      hash[key] =
        case hint = hints[key]
        when :boolean
          Tk.boolean(value)
        when :symbol
          value.to_sym
        when :float
          Float(value)
        else
          value
        end
    end

    hash
  elsif first =~ /^-/
    ::Hash[each_slice(2).map{|key, value|
      key = key.sub(/^-/, '').to_sym

      case hint = hints[key]
      when :boolean
        [key, Tk.boolean(value)]
      when :symbol
        [key, value.to_sym]
      when :float
        [key, Float(value)]
      else
        [key, value]
      end
    }]
  else
    self
  end
end

#to_tclObject



13
14
15
# File 'lib/ffi-tk/core_extensions.rb', line 13

def to_tcl
  TclString.new('{' << map(&:to_tcl).compact.join(' ') << '}')
end