Class: Object

Inherits:
BasicObject
Defined in:
lib/puppet_x/puppetlabs/swagger/fixnumify.rb,
lib/puppet_x/puppetlabs/swagger/symbolize_keys.rb

Instance Method Summary (collapse)

Instance Method Details

Method: Object#fixnumify

Defined in:
lib/puppet_x/puppetlabs/swagger/fixnumify.rb

- (Object) fixnumify



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/puppet_x/puppetlabs/swagger/fixnumify.rb', line 2

def fixnumify
  if self.respond_to? :to_i and self.to_i.to_s == self
    # If we can cast it to a Fixnum without losing anything do it.
    self.to_i
  elsif self.is_a? Array
    # If it's an Array, use Enumerable#map to recursively call this method
    # on each item.
    self.map {|item| item.fixnumify }
  elsif self.is_a? Hash
    # If it's a Hash, recursively call this method on each value.
    self.merge( self ) {|k, val| val.fixnumify }
  else
    # If for some reason we run into something else, just return
    # it unmodified; alternatively you could throw an exception.
    self
  end
end

Method: Object#symbolize_keys

Defined in:
lib/puppet_x/puppetlabs/swagger/symbolize_keys.rb

- (Object) symbolize_keys



2
3
4
5
6
# File 'lib/puppet_x/puppetlabs/swagger/symbolize_keys.rb', line 2

def symbolize_keys
  return self.inject({}){|memo,(k,v)| memo[k.to_sym] = v.symbolize_keys; memo} if self.is_a? Hash
  return self.inject([]){|memo,v    | memo           << v.symbolize_keys; memo} if self.is_a? Array
  return self
end