Class: Ick::Wrap

Inherits:
Base
  • Object
show all
Defined in:
lib/ick/wrap.rb

Direct Known Subclasses

Guard, Split

Instance Method Summary collapse

Methods inherited from Base

belongs_to, #evaluate, evaluates_in_calling_environment, evaluates_in_value_environment, #returns, returns_result, returns_value, underscore

Instance Method Details

#invokeObject



81
82
83
# File 'lib/ick/wrap.rb', line 81

def invoke
  raise 'subclass should override and invoke invoke_wrapped'
end

#invoke_wrapped(value, wrapper_class, *additional_arguments, &proc) ⇒ Object



75
76
77
78
79
# File 'lib/ick/wrap.rb', line 75

def invoke_wrapped(value, wrapper_class, *additional_arguments, &proc)
  wrapped_value = wrap(value, wrapper_class, *additional_arguments)
  wrapped_result = evaluate(wrapped_value, proc)
  returns(unwrap(wrapped_value, wrapper_class), unwrap(wrapped_result, wrapper_class))
end

#unwrap(wrapped, wrapper_class) ⇒ Object



71
72
73
# File 'lib/ick/wrap.rb', line 71

def unwrap(wrapped, wrapper_class)
  wrapped.respond_to?(:__value__) ? wrapped.__value__ : wrapped
end

#wrap(value, wrapper_class, *additional_arguments) ⇒ Object



67
68
69
# File 'lib/ick/wrap.rb', line 67

def wrap(value, wrapper_class, *additional_arguments)
  wrapper_class.new(value, *additional_arguments)
end