Class: Commander::HelpFormatter::Context
- Defined in:
- lib/commander/help_formatters.rb
Overview
Exposes target's binding to an ERB template, letting the template reference target's instance variables and private methods as if they were local variables/bare method calls. Subclasses can inject additional template-local variables by overriding #decorate_binding.
Direct Known Subclasses
Instance Method Summary collapse
-
#decorate_binding(_bind) ⇒ Object
No-op, override in subclasses.
-
#get_binding ⇒ Object
The (possibly decorated) binding of target, suitable for passing to ERB#result.
-
#initialize(target) ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize(target) ⇒ Context
Returns a new instance of Context.
21 22 23 |
# File 'lib/commander/help_formatters.rb', line 21 def initialize(target) @target = target end |
Instance Method Details
#decorate_binding(_bind) ⇒ Object
No-op, override in subclasses.
35 36 |
# File 'lib/commander/help_formatters.rb', line 35 def decorate_binding(_bind) end |
#get_binding ⇒ Object
The (possibly decorated) binding of target, suitable for passing to ERB#result.
28 29 30 31 32 |
# File 'lib/commander/help_formatters.rb', line 28 def get_binding @target.instance_eval { binding }.tap do |bind| decorate_binding(bind) end end |