Last active
August 29, 2015 14:26
-
-
Save krisleech/3af245a5455f8a2a17d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DoSomething has dependency on Configuration and pulls default from Configuration | |
# | |
module MyThingy | |
class DoSomething | |
def call(input, suffix = nil) | |
input + (suffix || default_suffix) | |
end | |
private | |
def default_suffix | |
MyThing.configuration.default_suffix | |
end | |
end | |
def configuration | |
@configuration ||= Configuration.new | |
end | |
class Configuration | |
attr_accessor :default_suffix | |
def default_suffix | |
@default_suffix ||= "_world" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configuration has dependency on DoSomething and pushes default to DoSomething | |
# | |
module MyThingy | |
class DoSomething | |
def call(input, suffix = nil) | |
input + (suffix || default_suffix) | |
end | |
class << self | |
attr_accessor :default_suffix | |
end | |
private | |
def default_suffix | |
self.class.default_suffix || '_world' | |
end | |
end | |
def configuration | |
@configuration ||= Configuration.new | |
end | |
class Configuration | |
attr_accessor :default_suffix | |
def default_suffix=(new_suffix) | |
DoSomething.default_suffix = new_suffix | |
end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyThingy.configuration.default_suffix = '_planet' | |
command = MyThing::DoSomething.new | |
command.call("mars") # => "mars_planet" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment