[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Calling super methods

Grzegorz Dostatni

9/30/2004 5:03:00 PM

15 Answers

Florian Frank

9/30/2004 8:10:00 PM

0

On Thu, 2004-09-30 at 21:05, Grzegorz Dostatni wrote:
> class Foo:
> def h(self):
> print "Foo"
>
> class Bar(Foo):
> def h(self):
> print "Bar"
>
> b = Bar()
>
> b.h()
> >> prints out "Bar"
> Foo.h(b)
> >> prints out "Foo"

class Foo
def h
puts "Foo"
end
end
class Bar < Foo
def h
puts "Bar"
end
end
b = Bar.new
Foo.instance_method(:h).bind(b).call # prints "Foo"

--
_="puts'_='+_.inspect+';'+_";puts'_='+_.inspect+';'+_



Andrew Johnson

9/30/2004 8:19:00 PM

0


On Thu, 30 Sep 2004 13:02:58 -0400, Grzegorz Dostatni
<grzegorz@ee.ualberta.ca> wrote:
>
> Is it possible to call a method of a superclass? Let's say I have a
> instance of class Bar ( subclassed from Foo).
> Both Foo and Bar define a function h()
>
> I want to call a.h() and have it go the Foo's implementation if it,
> without going through the super() call (ie. do it from outside the
> object).
>
> I have a code in python that does it:
>
> class Foo:
> def h(self):
> print "Foo"
>
> class Bar(Foo):
> def h(self):
> print "Bar"
>
> b = Bar()
>
> b.h()
>>> prints out "Bar"
> Foo.h(b)
>>> prints out "Foo"

Perhaps there's a shorter call sequence, but ...

class Foo
def h; puts "foo";end
end
class Bar < Foo
def h; puts "bar";end
end

a = Bar.new
a.h #=> 'bar'

## hardcode the call-up class:
Foo.instance_method(:h).bind(a).call #=> 'foo'

## more dynamic call-up:
a.class.superclass.instance_method(:h).bind(a).call #=> 'foo'

## Or, add dynamic call_up to the Object class:
class Object
def supercede(meth)
self.class.superclass.instance_method(meth).bind(self).call
end
alias :call_up :supercede
end

a.h #=> 'bar'
a.supercede(:h) #=> 'foo'
a.call_up(:h) #=> 'foo'
__END__

--
Andrew L. Johnson http://www.s...
They're not soaking, they're rusting!
-- my wife (on my dishwashing habits)

Florian Frank

9/30/2004 8:41:00 PM

0

On Thu, 2004-09-30 at 22:20, Andrew Johnson wrote:
> ## Or, add dynamic call_up to the Object class:
> class Object
> def supercede(meth)
> self.class.superclass.instance_method(meth).bind(self).call
> end
> alias :call_up :supercede
> end
>
> a.h #=> 'bar'
> a.supercede(:h) #=> 'foo'
> a.call_up(:h) #=> 'foo'
> __END__

supercede is nice. To build on that:

[...]
class Object
def supercede(meth, n = 1)
klass = (1..n).inject(self.class) do |klass,|
klass.__send__ :superclass
end
klass.instance_method(meth).bind(self).call
end
end

a.h #=> 'bar'
a.supercede(:h) #=> 'foo'
a.supercede(:h, 2) #=> 'foobar'

--
_="puts'_='+_.inspect+';'+_";puts'_='+_.inspect+';'+_



MiG

9/30/2004 9:36:00 PM

0


Hello,

is there anyone betters in QTRuby or Korundum? Of course, there are
examples in the tgz, but I'm especially concerned about UIC - creating
widgets on the fly from XML.

I can run the example and create widget but don't know what to do
further. For instance I have created some buttons in Designer and now
don't know how to access them in Ruby.

One example is better than 10GB manual :-) so I please anyone to write
preferably complete tutorial. I think ruby+kde/qt+xml could be VERY
powerful thing but people are lazy and want to learn everything as soon
as possible. Usually the best thing is not the winning :-(
If I'll tell my chief about Korundum, he would probably say that's
great but without manual we will prefer Java in the future.

Thank you!

MiG



Alexander Kellett

9/30/2004 9:46:00 PM

0

On Fri, Oct 01, 2004 at 06:36:23AM +0900, MiG wrote:
> One example is better than 10GB manual :-) so I please anyone to write
> preferably complete tutorial. I think ruby+kde/qt+xml could be VERY
> powerful thing but people are lazy and want to learn everything as soon
> as possible. Usually the best thing is not the winning :-(
> If I'll tell my chief about Korundum, he would probably say that's
> great but without manual we will prefer Java in the future.

you make an excellent point.
i'm in a mood to improve my ability
to write english and to improve a few
little qt/ruby apps that i made. i'll
do a full tutorial on the development
of a given application. i've never
used qtdesigner either. so the tutorial
will be written from the point of a
newbie for a newbie :)

Alex


Richard Dale

9/30/2004 10:16:00 PM

0

Alexander Kellett wrote:

> On Fri, Oct 01, 2004 at 06:36:23AM +0900, MiG wrote:
>> One example is better than 10GB manual :-) so I please anyone to write
>> preferably complete tutorial. I think ruby+kde/qt+xml could be VERY
>> powerful thing but people are lazy and want to learn everything as soon
>> as possible. Usually the best thing is not the winning :-(
>> If I'll tell my chief about Korundum, he would probably say that's
>> great but without manual we will prefer Java in the future.
>
> you make an excellent point.
> i'm in a mood to improve my ability
> to write english and to improve a few
> little qt/ruby apps that i made. i'll
> do a full tutorial on the development
> of a given application. i've never
> used qtdesigner either. so the tutorial
> will be written from the point of a
> newbie for a newbie :)
All I've done is take existing .ui files and make sure they can either be
compiled to ruby with the rbuic tool, or read in at runtime via
QUI::WidgetFactory.create. I'm a newbie too. So we really do need examples.
Is there a Qt Designer tutorial that could be translated from C++ to ruby
like I did with the cannon game tutorial? Thats a lot easier than starting
from scratch.

I find the Qt Designer UI takes a bit of getting used to. I was expecting to
be able to drag widgets off the palette like you can in Apple's Interface
Builder. Instead you click on the widget on the palette, and it puts the
cursor in 'place widget' mode. It took me about 10 mins to work out what
that was about. If you double click on the palette it gets stuck in 'place
widget' mode..

-- Richard

Richard Dale

9/30/2004 10:26:00 PM

0

Richard Dale wrote:

> Alexander Kellett wrote:
>
>> On Fri, Oct 01, 2004 at 06:36:23AM +0900, MiG wrote:
>>> One example is better than 10GB manual :-) so I please anyone to write
>>> preferably complete tutorial. I think ruby+kde/qt+xml could be VERY
>>> powerful thing but people are lazy and want to learn everything as soon
>>> as possible. Usually the best thing is not the winning :-(
>>> If I'll tell my chief about Korundum, he would probably say that's
>>> great but without manual we will prefer Java in the future.
>>
>> you make an excellent point.
>> i'm in a mood to improve my ability
>> to write english and to improve a few
>> little qt/ruby apps that i made. i'll
>> do a full tutorial on the development
>> of a given application. i've never
>> used qtdesigner either. so the tutorial
>> will be written from the point of a
>> newbie for a newbie :)
> All I've done is take existing .ui files and make sure they can either be
> compiled to ruby with the rbuic tool, or read in at runtime via
> QUI::WidgetFactory.create. I'm a newbie too. So we really do need
> examples. Is there a Qt Designer tutorial that could be translated from
> C++ to ruby like I did with the cannon game tutorial? Thats a lot easier
> than starting from scratch.
Actually there is a Qt Designer tutorial:

http://doc.trolltech.com/3.3/designer-man...

It just needs expanding to show how you generate ruby code with rbuic, and
then build the complete app.

Alexander Kellett

9/30/2004 10:29:00 PM

0

On Fri, Oct 01, 2004 at 07:20:01AM +0900, Richard Dale wrote:
> All I've done is take existing .ui files and make sure they can either be
> compiled to ruby with the rbuic tool, or read in at runtime via
> QUI::WidgetFactory.create. I'm a newbie too. So we really do need examples.
> Is there a Qt Designer tutorial that could be translated from C++ to ruby
> like I did with the cannon game tutorial? Thats a lot easier than starting
> from scratch.

i prefer widgetfactory.create
the entire rbuic / uic idea
disgusts me.

anyways. good point about previous
work :). i'll check.

> I find the Qt Designer UI takes a bit of getting used to. I was expecting to
> be able to drag widgets off the palette like you can in Apple's Interface
> Builder. Instead you click on the widget on the palette, and it puts the
> cursor in 'place widget' mode. It took me about 10 mins to work out what
> that was about. If you double click on the palette it gets stuck in 'place
> widget' mode.

i still want to rewrite qt designer :)
still hate it :P
Alex


Henrik Horneber

9/30/2004 10:37:00 PM

0

Richard Dale wrote:

> Alexander Kellett wrote:
>
>
>>On Fri, Oct 01, 2004 at 06:36:23AM +0900, MiG wrote:
>>
>>>One example is better than 10GB manual :-) so I please anyone to write
>>>preferably complete tutorial. I think ruby+kde/qt+xml could be VERY
>>>powerful thing but people are lazy and want to learn everything as soon
>>>as possible. Usually the best thing is not the winning :-(
>>>If I'll tell my chief about Korundum, he would probably say that's
>>>great but without manual we will prefer Java in the future.
>>
>>you make an excellent point.
>>i'm in a mood to improve my ability
>>to write english and to improve a few
>>little qt/ruby apps that i made. i'll
>>do a full tutorial on the development
>>of a given application. i've never
>>used qtdesigner either. so the tutorial
>>will be written from the point of a
>>newbie for a newbie :)
>
> All I've done is take existing .ui files and make sure they can either be
> compiled to ruby with the rbuic tool, or read in at runtime via
> QUI::WidgetFactory.create. I'm a newbie too. So we really do need examples.
> Is there a Qt Designer tutorial that could be translated from C++ to ruby
> like I did with the cannon game tutorial? Thats a lot easier than starting
> from scratch.
>
> I find the Qt Designer UI takes a bit of getting used to. I was expecting to
> be able to drag widgets off the palette like you can in Apple's Interface
> Builder. Instead you click on the widget on the palette, and it puts the
> cursor in 'place widget' mode. It took me about 10 mins to work out what
> that was about. If you double click on the palette it gets stuck in 'place
> widget' mode..
>
> -- Richard
>

I hope I am not pointing out the obvious, but the QtAssistant has a
section dedicated to using .uic files from code. In C++ of course. You
find it under the QtDesigner Manual, which seemed a little odd to me at
first, because it deals with using the Widgets from code.

Seems using the WidgetFactory is key.

Just in case you didn't know that. :)



Henrik Horneber

9/30/2004 10:38:00 PM

0

Richard Dale wrote:

> Richard Dale wrote:
>
>
>>Alexander Kellett wrote:
>>
>>
>>>On Fri, Oct 01, 2004 at 06:36:23AM +0900, MiG wrote:
>>>
>>>>One example is better than 10GB manual :-) so I please anyone to write
>>>>preferably complete tutorial. I think ruby+kde/qt+xml could be VERY
>>>>powerful thing but people are lazy and want to learn everything as soon
>>>>as possible. Usually the best thing is not the winning :-(
>>>>If I'll tell my chief about Korundum, he would probably say that's
>>>>great but without manual we will prefer Java in the future.
>>>
>>>you make an excellent point.
>>>i'm in a mood to improve my ability
>>>to write english and to improve a few
>>>little qt/ruby apps that i made. i'll
>>>do a full tutorial on the development
>>>of a given application. i've never
>>>used qtdesigner either. so the tutorial
>>>will be written from the point of a
>>>newbie for a newbie :)
>>
>>All I've done is take existing .ui files and make sure they can either be
>>compiled to ruby with the rbuic tool, or read in at runtime via
>>QUI::WidgetFactory.create. I'm a newbie too. So we really do need
>>examples. Is there a Qt Designer tutorial that could be translated from
>>C++ to ruby like I did with the cannon game tutorial? Thats a lot easier
>>than starting from scratch.
>
> Actually there is a Qt Designer tutorial:
>
> http://doc.trolltech.com/3.3/designer-man...
>
> It just needs expanding to show how you generate ruby code with rbuic, and
> then build the complete app.
>
>


duh, I replied a second too slow. :/