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
81 82 83 |
# File 'lib/rya/core_extensions.rb', line 81 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.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rya/core_extensions.rb', line 86 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 |