Skip to content

Instantly share code, notes, and snippets.

@lukelex
Created June 2, 2012 17:29
Show Gist options
  • Select an option

  • Save lukelex/2859271 to your computer and use it in GitHub Desktop.

Select an option

Save lukelex/2859271 to your computer and use it in GitHub Desktop.
WeekDays Metaprogrammed example
class Week
WEEKDAYS = %w( :segunda_feira, :terca_feira, :quarta_feira, :quinta_feira, :sexta_feira )
def custom_attr_accessor(attr)
self.class_eval("def #{attr};@#{attr};end")
self.class_eval("def #{attr}=(val);@#{attr}=val;end")
end
WEEKDAYS.each do |day|
custom_attr_accessor day
end
def initialize(args)
args.each do |key, value|
self.send(key, value)
end
end
def dias_true
"[" + WEEKDAYS.select { |day| self.send(day) == true }.join(",") + "]"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment