class Dottie::Freckle

Public Class Methods

new(obj) click to toggle source

Creates a new Freckle to wrap the supplied object.

# File lib/dottie/freckle.rb, line 8
def initialize(obj)
  case obj
  when Hash, Array
    @_wrapped_object = obj
  else
    raise TypeError, 'must be a Hash or Array'
  end
end

Public Instance Methods

array() click to toggle source

Returns the wrapped Array, and raises an error if the wrapped object is not an Array.

# File lib/dottie/freckle.rb, line 29
def array
  wrapped_object(Array)
end
hash() click to toggle source

Returns the wrapped Hash, and raises an error if the wrapped object is not a Hash.

# File lib/dottie/freckle.rb, line 21
def hash
  wrapped_object(Hash)
end
inspect() click to toggle source
# File lib/dottie/freckle.rb, line 45
def inspect
  "<Dottie::Freckle #{wrapped_object.inspect}>"
end
method_missing(method, *args) click to toggle source
# File lib/dottie/freckle.rb, line 49
def method_missing(method, *args)
  wrapped_object.send(method, *args)
end
wrapped_object(type = nil) click to toggle source

Returns the wrapped object, and raises an error if a type class is provided and the wrapped object is not of that type.

# 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