Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/rubble/dsl.rb

Instance Method Summary collapse

Instance Method Details

#dsl_accessor(*symbols) ⇒ Object

Create a DSL style accessor

Works like :attr_accessor, with the difference that the getter has an optional parameter that sets the property when present.

class Processor

dsl_accessor :plan

end

Examples:

Create a mutable DLS style property named ‘plan’

Parameters:

  • symbols (Array)

    names of the properties to create



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubble/dsl.rb', line 14

def dsl_accessor(*symbols)
    symbols.each do |symbol|
        class_eval %{
            def #{symbol}(value = nil)
                if value.nil?
                    @#{symbol}
                else
                    @#{symbol} = value
                end
            end

            def #{symbol}=(value)
                @#{symbol} = value
            end
        }
    end
end