Im not familiar on dependency injection
Remove Car's explicit reference to Engine by using dependency injection.
class Car
attr_reader :engine
def engine
@engine ||= Engine.new(4)
end
def move
engine.accelerate
end
end
class Engine
attr_reader :cylinders
def initialize(cylinders)
@cylinders = cylinders
end
def accelerate
end
end
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/3673d7f3-b4b2-4ffb-881c-d2b6c4169d64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.