Class: TkObject

Inherits:
TkKernel
  • Object
show all
Defined in:
tkutil/tkutil.c,
lib/tk.rb

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args) ⇒ Object



4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
# File 'lib/tk.rb', line 4923

def method_missing(id, *args)
  name = id.id2name
  case args.length
  when 1
    if name[-1] == ?=
      configure name[0..-2], args[0]
      args[0]
    else
      configure name, args[0]
      self
    end
  when 0
    begin
      cget(name)
    rescue
      if self.kind_of?(TkWindow) && name != "to_ary" && name != "to_str"
        fail NameError,
             "unknown option '#{id}' for #{self.inspect} (deleted widget?)"
      else
        super(id, *args)
      end
#        fail NameError,
#             "undefined local variable or method `#{name}' for #{self.to_s}",
#             error_at
    end
  else
    super(id, *args)
#      fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at
  end
end