lib/mascherari/attr_masked.rb in mascherari-0.0.1 vs lib/mascherari/attr_masked.rb in mascherari-0.0.2

- old
+ new

@@ -1,24 +1,21 @@ module Mascherari module AttrMasked def attr_masked(*attrs, options) attrs.each do |attr| - formatter = "#{attr}_format" - masked = "#{attr}_masked" - unmasked = "#{attr}_unmasked" - ivar = "@#{formatter}" + class_eval %{ + def #{attr}_format + @#{attr}_format ||= Formatter.new(#{options}) + end - define_method formatter do - instance_variable_get(ivar) || instance_variable_set(ivar, Formatter.new(options)) - end + def #{attr}_masked + #{attr}_format.mask #{attr} + end - define_method masked do - send(formatter).mask send(attr) - end - - define_method unmasked do - send(formatter).unmask send(attr) - end + def #{attr}_unmasked + #{attr}_format.unmask #{attr} + end + } end end end end