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