Skip to content

Instantly share code, notes, and snippets.

@vpacher
Created April 14, 2011 10:32
Show Gist options
  • Select an option

  • Save vpacher/919237 to your computer and use it in GitHub Desktop.

Select an option

Save vpacher/919237 to your computer and use it in GitHub Desktop.
ProspFmBitmapMethods = [:prosp_fm_sm, :prosp_fm_gay, :prosp_fm_bim, :prosp_fm_nondism, :prosp_fm_sf, :prosp_fm_les, :prosp_fm_bif, :prosp_fm_nondisf]
ProspFmBitmapMethods.each_with_index do |method, offset|
module_eval <<-EVAL, __FILE__, __LINE__
def #{method}
self.prospfm_bm & #{1 << offset}
end
def #{method}?
#{method} > 0
end
def #{method}=(new_val)
val = new_val.match(/(true|t|yes|y|1)$/i) != nil if new_val.is_a?(String)
val = (val.is_a?(TrueClass) || val.is_a?(FalseClass)) ? (val ? 1 : 0) : val
if val == 0
self.prospfm_bm &= #{ProspFmBitmapMethods.enum_with_index.collect { |mt, i| ((mt == method) ? 0 : 1) << i }.sum}
else
self.prospfm_bm |= #{1 << offset}
end
new_val
end
EVAL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment