From: Eric Armstrong Date: 2006-06-14T04:22:17+09:00 Subject: Re: How to invoke a run method??? Thanks for the additional explanation. I'll mull it over. The difference between instance and class methods is crystal clear in my java mind, but my ruby needs more educating. To make matter works, I /tried/ Foo::Main.new.run --but I must have inadvertently done so when run was a class method. Have to fire up the gray cells... :_) ara.t.howard@noaa.gov wrote: > On Tue, 13 Jun 2006, Eric Armstrong wrote: > >> This is pretty ridiculous, but I have tried >> virtually every combination of class and module >> definitions that I can think of, all without >> success: >> >> I started with an old Post by Ara Howard: >> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/193039 >> >> module Foo >> class Main >> ... >> end >> end >> Foo::Main.run(ARGV, ENV) if __FILE__ == $0 > > Foo::Main.new.run(ARGV, ENV) if __FILE__ == $0 > ^^^ > ^^^ > ^^^ > >> Then I found the ERB program at >> http://stuff.mit.edu/afs/sipb/project/ruby-lang/bin/erb >> >> That one reverses class & module: >> >> class ERB >> module Main >> def run > > def self.run > >> puts "Running" >> end >> end >> end >> Foo::Main.run if __FILE__ == $0 > > > >> What the heck is wrong with this picture? >> (thanks in advance) > > in both situations you are reversing the notion of class/module and > instance > methods. in the first case you call a class method when it should be an > instance method, in the second you define an instance methods and then > try to > call a class method. > > module M > def self.foo > 'this is a class/module method' > end > def bar > 'this is an instance method' > end > end > > we can do > > M.foo > > class C > include M > end > > C.new.bar > > > > alternatively we can have > > class C > def self.foo > 'this is a class/module method' > end > def bar > 'this is an instance method' > end > end > > and do > > C.foo > > C.new.bar > > make sense? > > -a