Skip to content

Instantly share code, notes, and snippets.

@ntl
Last active October 7, 2017 14:46

Revisions

  1. ntl revised this gist Oct 7, 2017. No changes.
  2. ntl revised this gist Oct 7, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion instance_method_arguments.rb
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ def approve(number, expiration_date, amount)
    def decline(number, expiration_date, amount)
    @approved.delete_if { |n, e, a|
    n == number && e == expiration_date && a == amount
    end
    end
    end
    end
    end
  3. ntl revised this gist Oct 7, 2017. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion initializer_arguments.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    class PaymentProcessor
    class InitializerArgumentsPaymentProcessor
    def initialize(number, expiration_date, amount)
    @number, @expiration_date, @amount = number, expiration_date, amount
    end
    2 changes: 1 addition & 1 deletion instance_arguments.rb → instance_method_arguments.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    class PaymentProcessor
    class InstanceMethodPaymentProcessor
    def call(number, expiration_date, amount)
    if SomeGateway.(number, expiration_date, amount)
    true
  4. ntl renamed this gist Oct 7, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. ntl created this gist Oct 7, 2017.
    31 changes: 31 additions & 0 deletions instance_arguments.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    class PaymentProcessor
    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
    27 changes: 27 additions & 0 deletions payment_processor.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    class PaymentProcessor
    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