[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:02268] Adding method to Object -- Why doesn't this work?

From: h.fulton@...
Date: 2000-03-30 18:26:57 UTC
List: ruby-talk #2268
Greetings, fellow Ruby enthusiasts.

Perhaps I have a fundamental misunderstanding here.

I am trying to add a method to Object. It doesn't
seem to be working.

See below. Can someone explain?

Thanks,
Hal Fulton

Program: ---------------------------------------
#!/bin/ruby

def Object.foobar
  print "I am the ultimate foobar!\n"
end

class Foo
  def foobar
    print "I am Foo::foobar... "
    if self.type.superclass.method_defined? "foobar"
      print "my parent has a foobar!\n"
    else
      print "my parent does NOT have a foobar.\n"
    end
    print "My parent is ", self.type.superclass, "\n"
  end
end
      
x = Foo.new
x.foobar

Output: ---------------------------------------
I am Foo::foobar... my parent does NOT have a foobar.
My parent is Object

In This Thread

Prev Next