Module: OptionBinder::Arguable

Defined in:
lib/optbind.rb

Instance Method Summary collapse

Instance Method Details

#binder(opts = {}, &blk) ⇒ Object Also known as: define, define_and_bind, bind



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/optbind.rb', line 248

def binder(opts = {}, &blk)
  unless @optbind
    if opts[:to] == :locals
      target, bind = TOPLEVEL_BINDING, :to_local_variables
    else
      target = opts[:target] || opts[:to]
      bind = (:to_local_variables if opts[:locals]) || opts[:bind] || ("to_#{opts[:via]}".to_sym if opts[:via])
    end

    @optbind = OptionBinder.new parser: opts[:parser], target: target, bind: bind
  end

  @optbind.instance_eval &blk if blk
  self.options = @optbind.parser
  @optbind
end

#binder=(bind) ⇒ Object



239
240
241
242
243
244
245
246
# File 'lib/optbind.rb', line 239

def binder=(bind)
  unless @optbind = bind
    class << self
      undef_method(:binder)
      undef_method(:binder=)
    end
  end
end

#define_and_parse!(opts = {}, &blk) ⇒ Object Also known as: bind_and_parse!



269
270
271
272
# File 'lib/optbind.rb', line 269

def define_and_parse!(opts = {}, &blk)
  define opts, &blk
  parse!
end

#order!(&blk) ⇒ Object



280
281
282
# File 'lib/optbind.rb', line 280

def order!(&blk)
  binder.order! self, &blk
end

#parse!Object



288
289
290
# File 'lib/optbind.rb', line 288

def parse!
  binder.parse! self
end

#parserObject



276
277
278
# File 'lib/optbind.rb', line 276

def parser
  self.options
end

#permute!Object



284
285
286
# File 'lib/optbind.rb', line 284

def permute!
  binder.permute! self
end