Class: Wrapper
- Inherits:
-
Object
- Object
- Wrapper
- Defined in:
- lib/nrser/rspex.rb
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
Returns a new instance of Wrapper.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/nrser/rspex.rb', line 62 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
99 100 101 |
# File 'lib/nrser/rspex.rb', line 99 def inspect to_s end |
#to_s ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/nrser/rspex.rb', line 91 def to_s if @description @description.to_s else "#<Wrapper ?>" end end |
#unwrap(context: nil) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/nrser/rspex.rb', line 83 def unwrap context: nil if context context.instance_exec &@block else @block.call end end |