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



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/optbind.rb', line 267

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



258
259
260
261
262
263
264
265
# File 'lib/optbind.rb', line 258

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



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

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

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



294
295
296
# File 'lib/optbind.rb', line 294

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

#parseObject



304
305
306
# File 'lib/optbind.rb', line 304

def parse
  binder.parse self
end

#parse!Object



308
309
310
# File 'lib/optbind.rb', line 308

def parse!
  binder.parse! self
end

#parserObject



300
301
302
# File 'lib/optbind.rb', line 300

def parser
  self.options
end