Class: EditInPlace::ExtendedBuilder
- Inherits:
-
Object
- Object
- EditInPlace::ExtendedBuilder
- Defined in:
- lib/edit_in_place/extended_builder.rb
Overview
A base class that allows one to easily and safely extend the Builder class with additional functionality. Every ExtendedBuilder contains a base builder to which it delegates all missing method calls. In this way, builder instances can be extended multiple times, like so:
base = Builder.new({...})
base.respond_to? :field # => true
hello_builder = HelloBuilder.new(base_builder, {...}) # a sub-class of ExtendedBuilder
hello_builder.respond_to? :hello # => true
hello_builder.respond_to? :field # => true
world_builder = WorldBuilder.new(hello_builder, {...}) # a sub-class of ExtendedBuilder
world_builder.respond_to? :world # => true
world_builder.respond_to? :hello # => true
world_builder.respond_to? :field # => true
A word of caution is in order, however! An ExtendedBuilder should never override a method on the base builder. While this may seem like a convenient way to add new methods to Builder, it can cause problems, since other methods further along in the chain will not call the overriden one. ExtendedBuilder is intended only for adding new methods, not mdifying existing ones.
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
The base builder instance which this ExtendedBuilder extends.
Instance Method Summary collapse
-
#initialize(base) ⇒ ExtendedBuilder
constructor
Creates a new ExtendedBuilder with the given base builder.
Constructor Details
#initialize(base) ⇒ ExtendedBuilder
Creates a new EditInPlace::ExtendedBuilder with the given base builder.
36 37 38 |
# File 'lib/edit_in_place/extended_builder.rb', line 36 def initialize(base) @base = base end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the base builder instance which this EditInPlace::ExtendedBuilder extends. It should quack like a Builder.
30 31 32 |
# File 'lib/edit_in_place/extended_builder.rb', line 30 def base @base end |