Created
November 22, 2009 12:14
-
-
Save pokle/240553 to your computer and use it in GitHub Desktop.
How to use Structs in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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