Module: Rya::CoreExtensions::Time
- Included in:
- Process
- Defined in:
- lib/rya/core_extensions.rb
Instance Method Summary collapse
-
#date_and_time(fmt = "%F %T.%L") ⇒ Object
Nicely format date and time.
-
#time_it(title = "", logger = nil, run: true) ⇒ Object
Run whatever is in the block and log the time it takes.
Instance Method Details
#date_and_time(fmt = "%F %T.%L") ⇒ Object
Nicely format date and time
110 111 112 |
# File 'lib/rya/core_extensions.rb', line 110 def date_and_time fmt = "%F %T.%L" Object::Time.now.strftime fmt end |
#time_it(title = "", logger = nil, run: true) ⇒ Object
Run whatever is in the block and log the time it takes.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rya/core_extensions.rb', line 115 def time_it title = "", logger = nil, run: true if run t = Object::Time.now yield time = Object::Time.now - t if title == "" msg = "Finished in #{time} seconds" else msg = "#{title} finished in #{time} seconds" end if logger logger.info msg else STDERR.puts msg end end end |