how can i make that the example below returns 'Hello, my name is test'?
module Barable
def self.append_features(base)
base.extend(ClassMethods)
super
end
module ClassMethods
def bar(bar) @bar = bar
end
end
end
class Foo
include Barable
bar "test"
def hi
puts "Hello, my bar is #{@bar}"
end
end
Foo.new.hi
Your subject line says class variables, but here you're using instance
variables (which always belong to whatever object is 'self' at a given
point in execution). Did you mean @@bar ?
def hi
puts "Hello, my bar is #{self.class.bar}"
end
end
Foo.new.hi
···
On Nov 3, 2004, at 7:14 AM, Florian Weber wrote:
how can i make that the example below returns 'Hello, my name is test'?
--
"Despite the surge of power you feel upon learning Ruby,
resist the urge to trip others or slap them in the bald head.
DO NOT LORD YOUR RUBYNESS OVER OTHERS!"
- Why the Lucky Stiff