Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

53 lines (41 sloc) 1.023 kb
class CodeEvent
def initialize(hash = {})
hash.each_pair do |attr,value|
define_attribute(attr)
self.send(writer_for(attr), value)
end
end
# Considering moving this to code that populates
# events so that this class isn't making assumptions
# about what it will be populated with
def full_method_name
class_name + "#" + method_name
end
def to_s
date.to_s + " " + class_name + "#" + method_name + ": " + complexity.to_s
end
private
def define_attribute(attr)
singleton_class.send(:public)
singleton_class.send(:attr_accessor, attr)
end
def singleton_class
class << self; self; end
end
def reader_for(sym)
sym.to_s.end_with?('=') ? sym.to_s.chop.to_sym : sym
end
def writer_for(sym)
(sym.to_s + "=").to_sym
end
def method_missing(sym, *args, &block)
if sym.to_s.end_with?('=')
define_attribute(reader_for(sym))
self.send(sym,*args)
elsif args.count == 0
return nil
else
super
end
end
end
Jump to Line
Something went wrong with that request. Please try again.