Skip to content

Instantly share code, notes, and snippets.

@pokle
Created November 22, 2009 12:14
Show Gist options
  • Save pokle/240553 to your computer and use it in GitHub Desktop.
Save pokle/240553 to your computer and use it in GitHub Desktop.
How to use Structs in Ruby
% irb
>> struct = Struct.new('Fabulous', :name, :id)
=> Struct::Fabulous
>> struct
=> Struct::Fabulous
>> class Foo < Struct::Fabulous
>> end
=> nil
>> f = Foo.new
=> #<struct Foo name=nil, id=nil>
>> f.name = 'Shona'
=> "Shona"
>> f.id = 'GenZ'
=> "GenZ"
>> f
=> #<struct Foo name="Shona", id="GenZ">
>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment