Class: Capsula::Wrapper
- Inherits:
-
Object
- Object
- Capsula::Wrapper
- Defined in:
- lib/capsula/wrapper.rb
Instance Attribute Summary collapse
-
#item ⇒ Object
Returns the value of attribute item.
-
#store ⇒ Object
readonly
Objects-wrapper which is giving to objects ability to encapsulate other objects.
Instance Method Summary collapse
-
#[]=(key, val) ⇒ Object
w=Capsula::Wrapper.new(1) => 1 w = 2 => 2 w => 1 w.a => 2.
-
#initialize(_object_) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #inspect ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(name, is_lookup_private = false) ⇒ Boolean
- #try(*a, &b) ⇒ Object
Constructor Details
#initialize(_object_) ⇒ Wrapper
Returns a new instance of Wrapper.
11 12 13 14 |
# File 'lib/capsula/wrapper.rb', line 11 def initialize _object_ @item = _object_ @store = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/capsula/wrapper.rb', line 48 def method_missing(method, *args, &block) if store.has_key?(method) store[method] else @item.send(method, *args, &block) end end |
Instance Attribute Details
#item ⇒ Object
Returns the value of attribute item.
9 10 11 |
# File 'lib/capsula/wrapper.rb', line 9 def item @item end |
#store ⇒ Object (readonly)
Objects-wrapper which is giving to objects ability to encapsulate other objects
8 9 10 |
# File 'lib/capsula/wrapper.rb', line 8 def store @store end |
Instance Method Details
#[]=(key, val) ⇒ Object
24 25 26 |
# File 'lib/capsula/wrapper.rb', line 24 def []= key, val @store[key] = val end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/capsula/wrapper.rb', line 28 def inspect @item.inspect end |
#respond_to?(name, is_lookup_private = false) ⇒ Boolean
32 33 34 |
# File 'lib/capsula/wrapper.rb', line 32 def respond_to? name, is_lookup_private = false self.store.include?(name) || @item.respond_to?(name, is_lookup_private) end |
#try(*a, &b) ⇒ Object
43 44 45 |
# File 'lib/capsula/wrapper.rb', line 43 def try *a, &b @item.try(*a, &b) end |