puts "hi from bar"
end
end
puts "hi from baz"
end
end
if klass.to_s == "Blah"
klass.send(:include,Bar)
else
klass.send(:include,Baz)
end
end
endOf course, we can change the conditional logic to fit our needs. Now we'll include this module into two classes:
include Foo
end
include Foo
end
Blah.new.hello # => 'hi from bar'
Barf.new.hello # => 'hi from baz'Yahoo! We get different behavior from each class without exposing the complexity to the end user.
1 comments:
yeah self.included is pretty slick.
Post a Comment