[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[OpenStruct] unexpected behaviour, bug?

benny

1/17/2005 12:16:00 PM

dear list,

just noticed an unexspected behaviour of the OpenStruct class:


require 'ostruct'
t = OpenStruct.new()
t.meth1 = []
t.send('meth1') << "hi"
puts t.meth1.inspect

this works, but

t.send('meth2') = [] # => test.rb:17: syntax error t.send('meth2') = []
puts t.meth2.inspect

is it a bug or am I missing something?

greetings,

benny

2 Answers

T. Onoma

1/17/2005 12:25:00 PM

0

On Monday 17 January 2005 07:16 am, benny wrote:
| dear list,
|
| just noticed an unexspected behaviour of the OpenStruct class:
|
|
| require 'ostruct'
| t = OpenStruct.new()
| t.meth1 = []
| t.send('meth1') << "hi"
| puts t.meth1.inspect
|
| this works, but
|
| t.send('meth2') = [] # => test.rb:17: syntax error t.send('meth2') = []
| puts t.meth2.inspect

aassignment itself isn't a method in Ruby, but assignment methods are (i.e.
setter methods), so try:

t.send('meth2=', [])

T


benny

1/17/2005 12:33:00 PM

0

trans. (T. Onoma) wrote:

> On Monday 17 January 2005 07:16 am, benny wrote:
> | dear list,
> |
> | just noticed an unexspected behaviour of the OpenStruct class:
> |
> |
> | require 'ostruct'
> | t = OpenStruct.new()
> | t.meth1 = []
> | t.send('meth1') << "hi"
> | puts t.meth1.inspect
> |
> | this works, but
> |
> | t.send('meth2') = [] # => test.rb:17: syntax error t.send('meth2') =
> | [] puts t.meth2.inspect
>
> aassignment itself isn't a method in Ruby, but assignment methods are
> (i.e. setter methods), so try:
>
> t.send('meth2=', [])
>
> T
second lesson :)

benny