File: struct.rb

package info (click to toggle)
ruby-extlib 0.9.16-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 576 kB
  • sloc: ruby: 7,014; makefile: 5
file content (17 lines) | stat: -rw-r--r-- 450 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Struct
  ##
  # 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}
  #
  # @return [Hash] Hash of instance variables in receiver, keyed by ivar name
  #
  # @api public
  def attributes
    h = {}
    each_pair { |k,v| h[k] = v }
    h
  end
end # class Struct