Jason Roelofs
3/12/2008 7:55:00 PM
Given this setup:
>> require 'ostruct'
=> false
>> o = OpenStruct.new
=> #<OpenStruct>
>> o.field = "this"
=> "this"
>> o.fold = "that"
=> "that"
>> o
=> #<OpenStruct field="this", fold="that">
The "nice" way:
>> o.methods - Object.methods - OpenStruct.instance_methods
=> ["fold", "fold=", "field", "field="]
Or maybe go one more level, to kick out the attr= methods:
(o.methods - Object.methods - OpenStruct.instance_methods).reject
{|method| method =~ /=$/ }
The "dirty" way:
>> o.instance_variable_get("@table")
=> {:field=>"this", :fold=>"that"}
Jason
On Wed, Mar 12, 2008 at 3:04 PM, Ed Hames <ehames@gmail.com> wrote:
> Dear rubyists,
>
> What's the best way to get the list of attributes of an OpenStruct?
>
> Thanks in advance,
> Edgardo
>
>