[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: OpenStruct,, know what keys are set
From:       Nobuyoshi Nakada <nobu () ruby-lang ! org>
Date:       2007-03-10 13:41:27
Message-ID: 200703101331.l2ADVo38002829 () sharui ! nakada ! kanuma ! tochigi ! jp
[Download RAW message or body]

Hi,

At Sat, 10 Mar 2007 17:29:18 +0900,
Aaron Smith wrote in [ruby-talk:242836]:
> I need to use an OpenStruct to mimic what an object acts like in another
> language. is it possible somehow to find what keys are set on an
> OpenStruct at any given time?

o = OpenStruct.new
o.foo = 1
o.bar = 2
p o.methods(false).grep(/[^=]$/) #=> ["bar", "foo"]

-- 
Nobu Nakada

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic