Return to Snippet

Revision: 2246
at January 23, 2007 06:56 by vanne


Initial Code
time_components = /(\d+):(\d+):(\d+)/.match("17:00:34")
time_components.instance_eval do
  def hours; self[1] end
  def minutes; self[2] end
  def seconds; self[3] end
end

time_components.hours # => "17" 
time_components.minutes # => "00" 
time_components.seconds # => "34" 
time_components.class # => MatchData

Initial URL
http://toolmantim.com/article/2006/11/29/instance_eval_brings_sexy_back

Initial Description
Using instance_eval to abstract values into meaningful methods

Initial Title
Just in time convenience methods

Initial Tags
ruby

Initial Language
Ruby