Skip to content

Instantly share code, notes, and snippets.

@josh7weaver
Last active August 29, 2015 14:13
Show Gist options
  • Save josh7weaver/7ca25ca23d5067cd65e5 to your computer and use it in GitHub Desktop.
Save josh7weaver/7ca25ca23d5067cd65e5 to your computer and use it in GitHub Desktop.
Ruby Dependency Injection
class Injectable
def can_you_see_me?
puts "SEEN!"
end
end
class Person
attr_accessor :seer
def initialize(seer)
@seer = seer
end
def see_me
seer.new.can_you_see_me?
end
end
person = Person.new(Injectable)
person.see_me
# outputs "SEEN!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment