Class: Wrapper
Instance Method Summary collapse
-
#initialize(description: nil, &block) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #unwrap(context: nil) ⇒ Object
Constructor Details
#initialize(description: nil, &block) ⇒ Wrapper
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/nrser/rspex.rb', line 63 def initialize description: nil, &block case description when Symbol @description = description.to_s if block raise ArgumentError, "Don't provide block with symbol" end if @description.start_with? '@' @block = Proc.new { instance_variable_get description } else @block = description.to_proc end else @description = description @block = block end end |
Instance Method Details
#inspect ⇒ Object
100 101 102 |
# File 'lib/nrser/rspex.rb', line 100 def inspect to_s end |
#to_s ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/nrser/rspex.rb', line 92 def to_s if @description @description.to_s else "#<Wrapper ?>" end end |
#unwrap(context: nil) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/nrser/rspex.rb', line 84 def unwrap context: nil if context context.instance_exec &@block else @block.call end end |