Class: Dottie::Freckle
- Inherits:
-
Object
- Object
- Dottie::Freckle
- Includes:
- Methods
- Defined in:
- lib/dottie/freckle.rb
Instance Method Summary collapse
-
#array ⇒ Object
Returns the wrapped Array, and raises an error if the wrapped object is not an Array.
-
#hash ⇒ Object
Returns the wrapped Hash, and raises an error if the wrapped object is not a Hash.
-
#initialize(obj) ⇒ Freckle
constructor
Creates a new Freckle to wrap the supplied object.
- #inspect ⇒ Object
- #method_missing(method, *args) ⇒ Object
-
#wrapped_object(type = nil) ⇒ Object
Returns the wrapped object, and raises an error if a type class is provided and the wrapped object is not of that type.
Methods included from Methods
Constructor Details
#initialize(obj) ⇒ Freckle
Creates a new Freckle to wrap the supplied object.
8 9 10 |
# File 'lib/dottie/freckle.rb', line 8 def initialize(obj) @_wrapped_object = obj end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
44 45 46 |
# File 'lib/dottie/freckle.rb', line 44 def method_missing(method, *args) wrapped_object.send(method, *args) end |
Instance Method Details
#array ⇒ Object
Returns the wrapped Array, and raises an error if the wrapped object is not an Array.
24 25 26 |
# File 'lib/dottie/freckle.rb', line 24 def array wrapped_object(Array) end |
#hash ⇒ Object
Returns the wrapped Hash, and raises an error if the wrapped object is not a Hash.
16 17 18 |
# File 'lib/dottie/freckle.rb', line 16 def hash wrapped_object(Hash) end |
#inspect ⇒ Object
40 41 42 |
# File 'lib/dottie/freckle.rb', line 40 def inspect "<Dottie::Freckle #{wrapped_object.inspect}>" end |
#wrapped_object(type = nil) ⇒ Object
Returns the wrapped object, and raises an error if a type class is provided and the wrapped object is not of that type.
32 33 34 35 36 37 38 |
# File 'lib/dottie/freckle.rb', line 32 def wrapped_object(type = nil) if type.nil? || @_wrapped_object.is_a?(type) @_wrapped_object else raise TypeError.new("expected #{type.name} but got #{@_wrapped_object.class.name}") end end |