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 separates 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



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

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