Module: DateTimeExt

Includes:
FormatTime
Included in:
Date, DateTime, Time
Defined in:
lib/formatted_times/date_time_ext.rb

Constant Summary

Constants included from FormatTime

FormatTime::FORMATTING_OPTIONS

Instance Method Summary collapse

Methods included from FormatTime

#get_strftime_string

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/formatted_times/date_time_ext.rb', line 4

def method_missing(sym, *args, &block)

  method_name = sym.to_s

  if method_name.starts_with? 'frmt_'
    if args.length.in?([1, 2]) and args[0].is_a?(String)
      strf_time_string = get_strftime_string(method_name, args[0], args[1])
    else
      strf_time_string = get_strftime_string(method_name)
    end
    return self.strftime(strf_time_string)
  else
    raise NoMethodError, "undefined method `#{method_name}' for #{self.inspect}:#{self.class.name}"
  end

rescue NoMethodError => e
  raise e, e.message.sub(self.inspect, self.inspect), e.backtrace
end