Class: Orange::Options

Inherits:
Object show all
Defined in:
lib/orange-core/magick.rb

Overview

Simple class for evaluating options and allowing us to access them.

Instance Method Summary collapse

Constructor Details

#initialize(*options, &block) ⇒ Options

Returns a new instance of Options.



147
148
149
150
151
# File 'lib/orange-core/magick.rb', line 147

def initialize(*options, &block)
  @options = options.extract_options!
  @options ||= {}
  instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args) ⇒ Object



157
158
159
160
161
162
163
164
165
166
# File 'lib/orange-core/magick.rb', line 157

def method_missing(key, *args)
  return (@options[key.to_s.gsub(/\?$/, '').to_sym].eql?(true)) if key.to_s.match(/\?$/)
  if args.empty?
    @options[key.to_sym]
  elsif(key.to_s.match(/\=$/))
    @options[key.to_s.gsub(/\=$/, '').to_sym] = (args.size == 1 ? args.first : args)
  else
    @options[key.to_sym] = (args.size == 1 ? args.first : args)
  end
end

Instance Method Details

#hashObject



153
154
155
# File 'lib/orange-core/magick.rb', line 153

def hash
  @options
end