Skip to content

Instantly share code, notes, and snippets.

@k-yagi
k-yagi / account_example_without_context.rb
Last active May 27, 2020 07:41 — forked from st33n/account_example_without_context.rb
Lean Architecture内でも紹介されているSteen Lehmann氏によるRubyにおけるDCI実装例。Interaction (role) からcontextへの依存を取り除いた書き方
#!/usr/bin/env ruby
# Lean Architecture example in Ruby - without ContextAccessor
# In this example, the context passes the needed roles into each method it
# invokes, and so the roles have no reference back to the context.
# Model class with no external dependenices. Includes a simple find method
# to create and store instances given an id - for illustration purposes only.
class Account
attr_reader :account_id, :balance
@k-yagi
k-yagi / account_example_with_context.rb
Last active May 27, 2020 07:02 — forked from st33n/account_example_with_context.rb
Lean Architecture内でも紹介されているSteen Lehmann氏によるRubyにおけるDCI実装例
#!/usr/bin/env ruby
# Lean Architecture example in Ruby - with ContextAccessor
# This example keeps interaction state in a "current context", represented
# by a ContextAccessor module. This can be mixed in to any class that needs
# access to the current context. It is implemented as a thread-local variable.
module ContextAccessor
def context
Thread.current[:context]