Skip to content

Instantly share code, notes, and snippets.

@wesmaldonado
Created October 23, 2009 16:37
Show Gist options
  • Save wesmaldonado/217020 to your computer and use it in GitHub Desktop.
Save wesmaldonado/217020 to your computer and use it in GitHub Desktop.
>> class OpenStruct
>> attr_accessor :id
>> end
=> nil
>> os = OpenStruct.new(:id => 1)
=> #<OpenStruct id=1>
>> os.id
=> nil
>> os.id = -1
=> -1
>> os.id
=> -1
Or...
>> class OpenStruct
>> def id
>> @table[:id]
>> end
>> end
=> nil
>> OpenStruct.new(:id => -1).id
=> -1
>> os = OpenStruct.new(:id => -1)
=> #<OpenStruct id=-1>
>> os.id
=> -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment