From: Andrew Choi Date: 2010-03-17T06:12:58+09:00 Subject: [ruby-core:28700] Re: [Feature #1400] Please add a method to enumerate fields in OpenStruct --1913079234-1268773977=:23085 Content-Type: multipart/alternative; boundary="1912791164-1268773977=:23085" MIME-Version: 1.0 --1912791164-1268773977=:23085 Content-transfer-encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 unsubscribe -----Original Message----- From: "Dan Rathbun" [redmine@ruby-lang.org] Date: 03/16/2010 04:39 PM To: ruby-core@ruby-lang.org Subject: Re: [ruby-core:28699] [Feature #1400] Please add a method to enumer= ate fields in OpenStruct Note: Original message sent as attachment ------------------------------------------------------------ Home Improvement Projects Click here to find experienced pros to help with your home improvement proje= ct. http://216.21.215.31/c?cp=3DQDUzL5DtxXzfSbgdUgxN8wAAKZVY5T0TJO72Jl_bl7CO2arf= AAYAAAAAAAAAAAAAAAAAAADNAAAAAAAAAAAAAAAAAAAShK6NZeY=3D --1912791164-1268773977=:23085 Content-transfer-encoding: quoted-printable Content-Type: text/html; charset=UTF-8 unsubscribe




-----Original Message-----
From: "Dan Rathbun" [redmine@ruby-lang.org]
Date: 03/16/2010 04:39 PM
To: ruby-core@ruby-lang.org
Subject: Re: [ruby-core:28699] [Feature #1400] Please add a method to enumer= ate fields in OpenStruct

Note: Original message sent as attachment
= = = = = = = =
= = = = = = = = = = = = =
  Home Improvement Projects<= /SPAN>
Click here to find experienced pros = to help with your home improvement project.
Click Here For More Informati= on
=
 
--1912791164-1268773977=:23085-- --1913079234-1268773977=:23085 Content-Type: message/rfc822; charset=UTF-8; name="0riginal_message" Content-Disposition: attachment; filename="0riginal_message" x-btFieldFwd: Yes Return-Path: X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on aspam007.roc2.bluetie.com X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=RDNS_NONE autolearn=disabled version=3.2.5 X-Original-To: achoi.myway@masc011.roc2.bluetie.com Delivered-To: achoi.myway@masc011.roc2.bluetie.com Received: from inbound005.roc2.bluetie.com (btroc2-lb.roc2.bluetie.com [10.200.2.8]) by mas000.roc2.bluetie.com (Postfix) with ESMTP id 58688D60121 for ; Tue, 16 Mar 2010 16:39:37 -0400 (EDT) Received: from carbon.ruby-lang.org ([221.186.184.68]) by inbound005.roc2.bluetie.com with inbound005 id twfY1d00Y1UxlsV01wfZvk; Tue, 16 Mar 2010 16:39:35 -0400 X-CMAE-Category: X-CMAE-Score: 0.00 X-CMAE-Analysis: v=1.1 cv=RpqRin20EikNPFC0NhhZyb7qtlqqDp4huBytcwwpogY= c=1 sm=1 a=ArQbOOmHeV8A:10 a=ICSgjsODHzIA:10 a=IkcTkHD0fZMA:10 a=fsK9XiHaSW3i/zTWbPYSMA==:17 a=w2PP7KgtAAAA:8 a=n_fk8HZggZt73Jy_5SkA:9 a=nCiXqMp3NW-viTWGPe0A:7 a=yVpoqy3WzZe-EXTlJ8zh8IQGiRMA:4 a=QEXdDO2ut3YA:10 a=Gq-bTBa4UauwmX4M:21 a=0YMPf0GKTFsJXbk3:21 a=fsK9XiHaSW3i/zTWbPYSMA==:117 Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id 7F5163C227284; Wed, 17 Mar 2010 05:39:25 +0900 (JST) Received: from svn.ruby-lang.org (svn.ruby-lang.org [210.251.121.215]) by carbon.ruby-lang.org (Postfix) with ESMTP id 6E7C03C21EB88 for ; Wed, 17 Mar 2010 05:39:20 +0900 (JST) Received: from ruby-lang.org (localhost [127.0.0.1]) by svn.ruby-lang.org (8.13.8+Sun/8.13.8) with ESMTP id o2GKdKEn023711 for ; Wed, 17 Mar 2010 05:39:20 +0900 (JST) Delivered-To: ruby-core@ruby-lang.org Date: Wed, 17 Mar 2010 05:39:20 +0900 Posted: Wed, 17 Mar 2010 05:39:20 +0900 From: Dan Rathbun Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:28699] [Feature #1400] Please add a method to enumerate fields in OpenStruct To: ruby-core@ruby-lang.org Message-Id: <4b9fec7854f4b_999c76fc303843@redmine.ruby-lang.org> X-ML-Name: ruby-core X-Mail-Count: 28699 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= X-Mailer: Redmine X-Redmine-Issue-Author: tpo X-Redmine-Issue-Id: 1400 X-Redmine-Journal-Id: 9022 X-Redmine-Project: ruby X-Redmine-Site: Ruby Issue Tracking System X-Redmine-Host: redmine.ruby-lang.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Precedence: bulk Lines: 32 List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: X-BtMT: Tue, 16 Mar 2010 16:39:37 -0400 (EDT) Issue #1400 has been updated by Dan Rathbun. This can be done right now. In several ways. # obj is an class OpenStruct which some number of members. ary = obj.methods(false).sort -> Array of attr getters and setters keys=[] ary.each {|i| keys.push(i) unless i.include?('=') } # keys is now an Array of fieldnames Also using existing method .marshal_dump which is really an attribute getter for @table (having a name different than the attribute.) Just noticed .table as a attribute getter alias of .marshal_dump, BUT .table is set protected, while .marshal_dump is not? Why is THAT? # obj is an class OpenStruct which some number of members. obj.marshal_dump.keys -> Array of keys obj.marshal_dump.values -> Array of values obj.marshal_dump.each {|k,v| ... } The danger in accessing the Hash directly is someone's going to modify it without removing the attr getter and setter methods defined in the class instance. Which by the way is a bug in the current OpenStruct. It's delete_field method does just that, lea ving the accessor methods without a key/value pair in @table. There is also an opposite bug. IF an attempt is made, to create a field who's name is already used as a method (without the '='); new_ostruct_member does NOT create the accessor methods, BUT does NOT return a indicator of success, so method_missing just goes ahead and adds the field to @table. Ex: obj.inspect='Sherlock Holmes' The unless block (line 72) in new_ostruct_member needs an else clause thats raises a NameError Exception "#{name} is already in use as a method of #{self}." Additionally, .marshal_load is flawed. It wipes out @table instead of appending; and puts everything in @table before checking it. The arg x should be typechecked as an OpenStruct or Hash; it should be put first in a temp reference. Looks like another ar gument may be needed for overwrite/ignore of matching keys. ---------------------------------------- http://redmine.ruby-lang.org/issues/show/1400 ---------------------------------------- http://redmine.ruby-lang.org AdGFib� --1913079234-1268773977=:23085--