Module: HabiticaClient::Task::DateAccessor

Included in:
HabiticaClient::Task
Defined in:
lib/habitica_client/task/date_accessor.rb

Instance Method Summary collapse

Instance Method Details

#date_accessor(*attributes) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/habitica_client/task/date_accessor.rb', line 7

def date_accessor(*attributes)
  attributes.each do |attribute|
    define_method("#{attribute}=") do |date|
      unless date.nil?
        instance_variable_set("@#{attribute}", DateTime.parse(date))
      end
    end

    define_method("#{attribute}") do
      instance_variable_get("@#{attribute}")
    end
  end
end