Module: TKXXS_CLASSES
- Defined in:
- lib/tkxxs/tkxxs_classes.rb
Overview
Creates dialogs for TKXXS
Defined Under Namespace
Classes: AskMultiLineD, AskSingleLineD, ChooseDirD, FileAndDirChooser, MultiChoiceD, OpenFileD, OpenFilesD, SaveFileD, SingleChoiceD, TextW
Class Method Summary collapse
-
.args_1(*args) ⇒ Object
Purpose: Interpret last argument always as +Hash#, independent from the number of arguments: * Searches for the first argument which is a Hash, from right to left, starting with the last argument.
-
.args_2(help, hash, question, *keys) ⇒ Object
Set the value of new variables from the values of the hash.
Class Method Details
.args_1(*args) ⇒ Object
Purpose:
Interpret last argument always as +Hash#, independent from the
number of arguments:
-
Searches for the first argument which is a Hash, from right to left, starting with the last argument. (TODO: Why not simply detect if the last argument is a Hash?)
-
If Hash exists:
** Move the hash to the last element of args. ** Set the element, where the Hash comes from to nil, if it was
not the last element.
** All other elements remain unchanged.
-
If no Hash exist:
** Sets the last element of args to {} ** All other elements remain unchanged.
Returns: The rearranged args.
Example:
def m1( c=nil,b=nil,a=nil,h=nil )
c, b, a, hash = args_1(c,b,a,h)
p [c, b, a, hash]
hash = {:a=>'aa',
:b=>'bb',
:c=>'cc'
}.merge(hash)
c = hash[:c] unless c
b = hash[:b] unless b
a = hash[:a] unless a
nil
end # m1
m1(:c,:b,:a, {:h=>'hh'}) # => [:c, :b, :a, {:h=>"hh"}]
m1(:c, {:h=>'hh'}) # => [:c, nil, nil, {:h=>"hh"}]
m1(:c) # => [:c, nil, nil, {}]
m1() # => [nil, nil, nil, {}]
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/tkxxs/tkxxs_classes.rb', line 65 def TKXXS_CLASSES.args_1( *args ) args = args.reverse args.each_with_index {|arg, i| if arg.class == Hash args[i] = nil args[0] = arg break end } args[0] = unless args[0] {} else ## Marshal.load(Marshal.dump( args[0] ) ) # Doesn't work because of Proc args[0].dup2! # args[0] must always be a Hash end args = args.reverse args end |
.args_2(help, hash, question, *keys) ⇒ Object
Set the value of new variables from the values of the hash.
New variables are always: question
and help
.
‘hash’ gets modified.
On the left side of the equal sign: always ‘help, hash, question’, thereafter the additional variables.
Arguments of args_2: ‘help,hash,question’ and then the (optional) hash-keys, which shall be assigned to the additional variables. :help and :question can be put at arbitrary position, or omitted. hash must have: :question.
If the variable help
and/or question
are already set (not equal nil
), then they leave unchanged.
EXAMPLE:
help = 'h'
hash = {
:help=>'heeelp',
:question=>'MyQuestion',
:title=>'MyTitle',
:SomethingElse=>'bla'
}
help, hash, question, title =
TKXXS_CLASSES.args_2( help, hash, question, :title)
# => ["h", {:SomethingElse=>"bla"}, "MyQuestion", "MyTitle"]
-
‘h’ in
help
not overwritten, becausehelp
was defined before; -
Every key in
hash
deleted, which corresponds to the args ofargs_2
; -
question
now set, because it was not defined before; -
title
set tohash[:title]
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/tkxxs/tkxxs_classes.rb', line 119 def TKXXS_CLASSES.args_2( help,hash,question,*keys ) hash.delete(:configSection) if hash[:configSection] q = hash.delete(:question) question = q unless question h = hash.delete(:help) help = h unless help values = [help,hash,question] keys.each {|key| val = hash.delete(key) values << val } values[1] = hash values end |