Class: BinData::BaseArgExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/bindata/base.rb

Overview

ArgExtractors take the arguments passed to BinData::Base.new and separate them into [value, parameters, parent].

Constant Summary collapse

@@empty_hash =
Hash.new.freeze

Class Method Summary collapse

Class Method Details

.extract(the_class, the_args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bindata/base.rb', line 16

def self.extract(the_class, the_args)
  args = the_args.dup
  value = parameters = parent = nil

  if args.length > 1 and args.last.is_a? BinData::Base
    parent = args.pop
  end

  if args.length > 0 and args.last.is_a? Hash
    parameters = args.pop
  end

  if args.length > 0
    value = args.pop
  end

  parameters ||= @@empty_hash

  return [value, parameters, parent]
end