In most Ruby code, the hash is used as simple data structures. It's not as efficient as something like this, and there are no definitions of the fields in these hashes, but they're passed around much like a struct in C or simple classes like this in Java. You can of course just do your own class like this:
class MyStruct attr_accessor :something, :something_else end
But Ruby also has a Struct class that can be used. You don't see it much though.
#!/usr/bin/env ruby Customer = Struct.new('Customer', :name, :email) c = Customer.new c.name = 'David Lightman' c.email = '[email protected]'
There's also OpenStruct.
#!/usr/bin/env ruby require 'ostruct' c = OpenStruct.new c.name = 'David Lightman' c.greeting = 'How about a nice game of chess?'
I've written about these things here.