RE: Fruit basket program in Ruby.NET

  • From: "Macarty, Jay {PBSG}" <Jay.Macarty@xxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sat, 5 Jan 2008 12:33:06 -0600

Jamal, 
Interesting observations and solutions with the existing syntax. As you
state, readability might be compromised somewhat with the latter
example; however, I'd think one could write a little utility class with
a static method that would take the object being created and the hash of
the properties, perform the tasks you illustrate and return an instance
of the object with the properties set. This might accomplish what you
were after while encapsulating the complexities of the eval logic
presented.


-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jamal Mazrui
Sent: Saturday, January 05, 2008 9:41 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Fruit basket program in Ruby.NET

I wish Ruby let one specify properties of an object when it is created,
like Python, Boo, or C# 3.0.  I've heard such syntax is being considered
for a future version.

I wanted to see how close I could get using current features of the Ruby
language.  I found that a single property could be set using syntax like
the following:

(btnAdd = Button.new).Text = "&Add"

Multiple properties could be set using a hash and the eval method with
syntax like the following:

tlp = TableLayoutPanel.new
{"ColumnCount" => 3, "RowCount" => 2}.each_pair {|property, value|
eval("tlp.#{property} = #{value}")}

Readability is definately sacrificed in the latter case, so the lines of
code saved may not be worth it!

Jamal

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: