Method: Choice::Option#initialize

Defined in:
lib/choice/option.rb

#initialize(options = {}, &block) ⇒ Option

You can instantiate an option on its own or by passing it a name and a block. If you give it a block, it will eval() the block and set itself up nicely.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/choice/option.rb', line 14

def initialize(options = {}, &block)
  # Here we store the definitions this option contains, to make to_a and
  # to_h easier.
  @choices = []      

  # If we got a block, eval it and set everything up.
  instance_eval(&block) if block_given?      

  # Is this option required?
  @required = options[:required] || false
  @choices << 'required'
end