Class: Representative::Base
- Inherits:
-
Object
- Object
- Representative::Base
- Defined in:
- lib/representative/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#current_subject ⇒ Object
(also: #subject)
Return the current “subject” of representation.
-
#initialize(subject = nil, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#representing(new_subject, &block) ⇒ Object
Evaluate a block with a specified object as #subject.
Constructor Details
#initialize(subject = nil, options = {}) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 |
# File 'lib/representative/base.rb', line 7 def initialize(subject = nil, = {}) @subjects = [subject] @inspector = [:inspector] || ObjectInspector.new @naming_strategy = [:naming_strategy] || :plain end |
Instance Method Details
#current_subject ⇒ Object Also known as: subject
Return the current “subject” of representation.
This object will provide element values where they haven’t been explicitly provided.
18 19 20 |
# File 'lib/representative/base.rb', line 18 def current_subject @subjects.last end |
#representing(new_subject, &block) ⇒ Object
Evaluate a block with a specified object as #subject.
26 27 28 |
# File 'lib/representative/base.rb', line 26 def representing(new_subject, &block) with_subject(resolve_value(new_subject), &block) end |