Calling super methods

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"

Greg

"When ideas fail, words come in very handy."
  - Goethe (1749-1832)

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"

···

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"

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

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__

···

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"

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

Grzegorz Dostatni 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).

Ah, this has been asked before. I attached my implementation. With this one you don't need to pass the method name.

Regards,
Florian Gross

superjump.rb (769 Bytes)

"Grzegorz Dostatni" <grzegorz@ee.ualberta.ca> schrieb im Newsbeitrag
news:Pine.LNX.4.44.0409301255520.11306-100000@e5-05.ee.ualberta.ca...

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).

May I ask why you need that? IMHO it's no good OO design practice to
explicitely select the method to invoke. Methods are overridden on
purpose, so if you have a sub class instance the sub class method should
be invoked. If you need special functionality that is present in the base
class method, then this is typically an indication that it should be
factored out of that method into a separate method.

Regards

    robert

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'

···

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__

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

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 :slight_smile: 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 :frowning:
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

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 :slight_smile:

Alex

···

On Fri, Oct 01, 2004 at 06:36:23AM +0900, MiG wrote:

One example is better than 10GB manual :slight_smile: 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 :frowning:
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.

Alexander Kellett wrote:

One example is better than 10GB manual :slight_smile: 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 :frowning:
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 :slight_smile:

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

···

On Fri, Oct 01, 2004 at 06:36:23AM +0900, MiG 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 :slight_smile:
still hate it :stuck_out_tongue:
Alex

···

On Fri, Oct 01, 2004 at 07:20:01AM +0900, Richard Dale wrote:

Richard Dale wrote:

Alexander Kellett wrote:

One example is better than 10GB manual :slight_smile: 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 :frowning:
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 :slight_smile:

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-manual-3.html

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

···

On Fri, Oct 01, 2004 at 06:36:23AM +0900, MiG wrote:

Richard Dale wrote:

Alexander Kellett wrote:

One example is better than 10GB manual :slight_smile: 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 :frowning:
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 :slight_smile:

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. :slight_smile:

···

On Fri, Oct 01, 2004 at 06:36:23AM +0900, MiG wrote:

Hi,

maybe you can find something here:

http://developer.kde.org/language-bindings/ruby/

He also translated some tutorials to ruby, but I think there are no examples
for using the designer.

Greetings

Mike

Richard Dale wrote:

Richard Dale wrote:

Alexander Kellett wrote:

One example is better than 10GB manual :slight_smile: 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 :frowning:
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 :slight_smile:

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-manual-3.html

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. :confused:

···

On Fri, Oct 01, 2004 at 06:36:23AM +0900, MiG wrote:

as is my normal opinion of tutorials...
this is just awful. *way* too long.
i want the *first page* of my
tutorial to already have something
pretty dang impressive on ones screen.
just hooks. people can fill in. don't
need to step by step. just teach ideas.
give them the possibility to make the
leaps by giving them the steps :slight_smile:
i'll write something myself for certain :stuck_out_tongue:
thanks for tutorial anyways.
nice to know that it exists :slight_smile:
cheers,
Alex

···

On Fri, Oct 01, 2004 at 07:30:01AM +0900, Richard Dale wrote:

Actually there is a Qt Designer tutorial:
http://doc.trolltech.com/3.3/designer-manual-3.html

yes,

there is *VERY* simple example of QYWidgetFactory only creating window
form .ui file:

QUI::WidgetFactory.loadImages ARGV[0]
w = QUI::WidgetFactory.create ARGV[1]
w.show()

But I don't know how to access it's components, etc.

Good documentation with many examples is needed. It's the best way how
to write KDE apps using Ruby and spread Ruby itself. Only few people
will use it else. I'm not C++ programmer, don't understand C++ well
and therefore can't get inspired from C++ code fastly. I think people
don't want to mess about tons of code, they need working examples. That
is why lack of documentation got rid of many good projects.

Jan Molic

···

Dne 6/10/2004, napsal "Michael Gebhart" <mail@miketech.net>:

Hi,

maybe you can find something here:

http://developer.kde.org/language-bindings/ruby/

He also translated some tutorials to ruby, but I think there are no examples
for using the designer.

Greetings

Mike