Class: Multidispatch::Store
- Inherits:
-
Object
- Object
- Multidispatch::Store
- Defined in:
- lib/multidispatch/store.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #get(klass, method_name, arity) ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
- #lock! ⇒ Object
- #locked? ⇒ Boolean
- #release! ⇒ Object
- #set(klass, method_name) ⇒ Object
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
6 7 8 9 |
# File 'lib/multidispatch/store.rb', line 6 def initialize @store = {} @locked = nil end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
4 5 6 |
# File 'lib/multidispatch/store.rb', line 4 def store @store end |
Instance Method Details
#get(klass, method_name, arity) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/multidispatch/store.rb', line 11 def get(klass, method_name, arity) class_methods = @store[klass.name] || {} methods = class_methods[method_name] || {} method_body = methods[-1] || methods[arity] raise NoMethodError unless method_body method_body end |
#lock! ⇒ Object
32 33 34 35 |
# File 'lib/multidispatch/store.rb', line 32 def lock! @locked = true self end |
#locked? ⇒ Boolean
28 29 30 |
# File 'lib/multidispatch/store.rb', line 28 def locked? @locked end |
#release! ⇒ Object
37 38 39 40 |
# File 'lib/multidispatch/store.rb', line 37 def release! @locked = nil self end |
#set(klass, method_name) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/multidispatch/store.rb', line 19 def set(klass, method_name) return nil if locked? class_methods = @store[klass.name] ||= {} methods = class_methods[method_name] ||= {} method = klass.instance_method(method_name) methods[method.arity] = method end |