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
#[], #[]=, #delete, #dottie_flatten, #dottie_keys, #fetch, #has_key?
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
49 50 51 |
# File 'lib/dottie/freckle.rb', line 49 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.
29 30 31 |
# File 'lib/dottie/freckle.rb', line 29 def array wrapped_object(Array) end |
#hash ⇒ Object
Returns the wrapped Hash, and raises an error if the wrapped object is not a Hash.
21 22 23 |
# File 'lib/dottie/freckle.rb', line 21 def hash wrapped_object(Hash) end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/dottie/freckle.rb', line 45 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.
37 38 39 40 41 42 43 |
# File 'lib/dottie/freckle.rb', line 37 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 |