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
51 52 53 |
# File 'lib/dottie/freckle.rb', line 51 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.
31 32 33 |
# File 'lib/dottie/freckle.rb', line 31 def array wrapped_object(Array) end |
#hash ⇒ Object
Returns the wrapped Hash, and raises an error if the wrapped object is not a Hash.
23 24 25 |
# File 'lib/dottie/freckle.rb', line 23 def hash wrapped_object(Hash) end |
#inspect ⇒ Object
47 48 49 |
# File 'lib/dottie/freckle.rb', line 47 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.
39 40 41 42 43 44 45 |
# File 'lib/dottie/freckle.rb', line 39 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 |