[fxruby-users] setting widget attributes

Mark Volkmann r.mark.volkmann at gmail.com
Tue Mar 28 17:53:23 EST 2006


On 3/28/06, Meinrad Recheis <meinrad.recheis at gmail.com> wrote:
> On 3/28/06, Mark Volkmann <r.mark.volkmann at gmail.com> wrote:
> > I'm trying to set attributes of widgets in subclasses like the following.
> >
> > class PersonTable < FXTable
> >   def initialize(owner)
> >     options = TABLE_COL_SIZEABLE
> >     super(owner, nil, 0, options)
> >
> >     visibleRows = 5
> >     ...
> >   end
> > end
> >
> > visibleRows doesn't get set.
> > However, if I do this
> >
> > self.visibleRows = 5
> >
> > then it does.
> >
> > Shouldn't it work without "self."?
>
> that's a common problem with ruby extensions. but i don't understand
> the underlying principle ;)

I think I do now, so I'll try to pass on what is happening.
When Ruby sees something like this

  foo bar

it starts by checking the current object referred to by self to see if
it has a method named "foo". If it does, that is used. If it doesn't,
the method search continues through singleton methods, class methods,
included module methods, and up the inheritance hierachy.

But what about a method named "foo="?
I assumed that if I wrote

  foo = bar

the same method search would apply. However, it does not. It will just
create a local variable named foo and assign bar to it. But if I write

  self.foo = bar

then it knows I'm invoking a method and it knows the receiver and will
look for a foo= method in the current object.

--
R. Mark Volkmann
Object Computing, Inc.



More information about the fxruby-users mailing list