>>>>> "E" == Eugine Kosenko <eugine_kosenko / yahoo.com> writes:


E> class Foo
E>    def Foo.greeting
E>       "Hello! I'm a #{Name}"
E>    end
E> end

E> class Bar1 < Foo
E>    Name = "Good Guy"
E> end

E> class Bar2 < Foo
E>    Name = "Bad Guy"
E> end

E> Bar1.greeting   # -> Hello! I'm a Good Guy
E> Bar2.greeting   # -> Hello! I'm a Bad Guy

E> This is does not work as well as I would try to define

E> class Foo
E>    Name = "Unknown Guy"
E> end

 Use an instance variable

pigeon% cat b.rb
#!/usr/bin/ruby
class Foo
   @name = "Unknown guy"
   def Foo.greeting
      "Hello! I'm a #{@name}"
   end
end

class Bar1 < Foo
   @name = "Good guy"
end

class Bar2 < Foo
   @name = "Bad guy"
end

p Bar1.greeting   # -> Hello! I'm a Good Guy
p Bar2.greeting   # -> Hello! I'm a Bad Guy
pigeon% 

pigeon% b.rb
"Hello! I'm a Good guy"
"Hello! I'm a Bad guy"
pigeon% 

E> Any ideas?

 Don't put a capital letter to 'guy' :-)

E> E-mail is preferred

 cc:

-- 

Guy Decoux