Class: GtfsReader::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/gtfs_reader/configuration.rb

Instance Method Summary collapse

Instance Method Details

#block_parameter(name, obj_class, *init_args) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/gtfs_reader/configuration.rb', line 17

def block_parameter(name, obj_class, *init_args)
  obj = nil
  define_singleton_method(name) do |*args, &block|
    obj ||= obj_class.new(*init_args)
    obj.instance_exec(obj, *args, &block) if block
    obj
  end
end

#parameter(*names) ⇒ Object

Creates simple configuration parameters which may be set by the user

Parameters:

  • names (Array<Symbol>)

    the names of the parameters to create



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/gtfs_reader/configuration.rb', line 5

def parameter(*names)
  names.each do |name|
    define_singleton_method(name) do |*values|
      if (value = values.first)
        instance_variable_set("@#{name}", value)
      else
        instance_variable_get("@#{name}")
      end
    end
  end
end