Class: Struct

Inherits:
Object show all
Defined in:
lib/gems/extlib-0.9.9/lib/extlib/struct.rb

Instance Method Summary collapse

Instance Method Details

#attributesHash

Get a hash with names and values of all instance variables.

class Foo < Struct.new(:name, :age, :gender); end
f = Foo.new("Jill", 50, :female)
f.attributes   #=> {:name => "Jill", :age => 50, :gender => :female}

Returns:

  • (Hash)

    Hash of instance variables in receiver, keyed by ivar name



12
13
14
15
16
# File 'lib/gems/extlib-0.9.9/lib/extlib/struct.rb', line 12

def attributes
  h = {}
  each_pair { |k,v| h[k] = v }
  h
end