Module: Zenity

Defined in:
lib/zenity.rb

Class Method Summary collapse

Class Method Details

.method_missing(m, options = false) ⇒ Object

Let’s just use method_missing instead of defining all of those.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/zenity.rb', line 5

def method_missing(m, options=false)
  # Check if the dialog box we have to show is allowed
  if [ :calendar, :entry, :error, :'file-selection', :info, :list,
       :notification, :progress, :question, :'text-info', :warning, :scale 
  ].include? m
    # It's in the array and everything seems to be fine
    ret = %x[ #{parseopts('zenity --' + m.to_s, options)} ]
  else
    # We don't know about this dialog, raise an error
    raise "Unknown dialog #{m}"
  end
  # Check if any of the options passed were invalid.
  if ret.rstrip == 'This option is not available. Please see --help for all possible usages.'
    # Write a message to STDERR if there were invalid options, but don't
    # raise an error.
    STDERR << "Invalid option"
  else
    # Everything looks fine. Return what we got.
    return ret
  end
end