Last active
October 7, 2017 14:46
-
-
Save ntl/dd530170aeec42d10a1474130f996cbb 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
class InitializerArgumentsPaymentProcessor | |
def initialize(number, expiration_date, amount) | |
@number, @expiration_date, @amount = number, expiration_date, amount | |
end | |
def call | |
if SomeGateway.(number, expiration_date, amount) | |
true | |
else | |
false | |
end | |
end | |
class Substitute | |
def call | |
@approved | |
end | |
def approve | |
@approved = true | |
end | |
def decline | |
@approved = false | |
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
class InstanceMethodPaymentProcessor | |
def call(number, expiration_date, amount) | |
if SomeGateway.(number, expiration_date, amount) | |
true | |
else | |
false | |
end | |
end | |
class Substitute | |
def initialize | |
@approved = [] | |
end | |
def call(number, expiration_date, amount) | |
@approved.any? do |n, e, a| | |
n == number && e == expiration_date && a == amount | |
end | |
end | |
def approve(number, expiration_date, amount) | |
@approved << [number, expiration_date, amount) | |
end | |
def decline(number, expiration_date, amount) | |
@approved.delete_if { |n, e, a| | |
n == number && e == expiration_date && a == amount | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that for the initializer arguments example, a class level call method can be added to give the class the same interface as instances of the instance methods arguments example. So you get both approaches: