我正在尝试了解 Ruby/Rails 中的依赖注入。如何删除对使用依赖注入Builder
的显式引用?Saw
class Builder
attr_reader :saw
def saw
@saw ||= Saw.new(4)
end
def cut_wood
Saw.saw
end
end
class Saw
attr_reader :blades
def initialize(blades)
@blades = blades
end
def saw
# do something
end
end