Class: Capsula::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/capsula/wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#itemObject

Returns the value of attribute item.



9
10
11
# File 'lib/capsula/wrapper.rb', line 9

def item
  @item
end

#storeObject (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

w=Capsula::Wrapper.new(1)

> 1

w = 2

> 2

w

> 1

w.a

> 2



24
25
26
# File 'lib/capsula/wrapper.rb', line 24

def []= key, val
  @store[key] = val
end

#inspectObject



28
29
30
# File 'lib/capsula/wrapper.rb', line 28

def inspect
  @item.inspect
end

#respond_to?(name, is_lookup_private = false) ⇒ Boolean

Returns:

  • (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