Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Product < ActiveRecord::Base
- ...
- # Sustainability Flags
- RECYCLED_BIT = 1 << 0
- RECYCLEABLE_BIT = 1 << 1
- BIODEGRADABLE_BIT = 1 << 2
- LOCAL_BIT = 1 << 3
- def recycled?
- (flags & RECYCLED_BIT) != 0
- end
- def recycled=(flag)
- if flag
- write_attribute("flags", flags | RECYCLED_BIT)
- else
- write_attribute("flags", flags & ~RECYCLED_BIT)
- end
- end
- def recyclable?
- (flags & RECYCLABLE_BIT) != 0
- end
- def recyclable=(flag)
- if flag
- write_attribute("flags", flags | RECYCLABLE_BIT)
- else
- write_attribute("flags", flags & ~RECYCLABLE_BIT)
- end
- end
- def biodegradable?
- (flags & BIODEGRADABLE_BIT) != 0
- end
- def biodegradable=(flag)
- if flag
- write_attribute("flags", flags | BIODEGRADABLE_BIT)
- else
- write_attribute("flags", flags & ~BIODEGRADABLE_BIT)
- end
- end
- def local?
- (flags & LOCAL_BIT) != 0
- end
- def local=(flag)
- if flag
- write_attribute("flags", flags | LOCAL_BIT)
- else
- write_attribute("flags", flags & ~LOCAL_BIT)
- end
- end
- ...
- end
Add Comment
Please, Sign In to add comment