Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
class Tag < ActiveRecord::Base def self.separator ',' end def self.tag_string(tags) Array(tags).select { |t| self === t }.map(&:name) * "#{separator} ".squeeze(' ') end end class Post < ActiveRecord::Base has_and_belong_to_many :tags do def to_s Tag.tag_string(self) end end end ------ class Tag < ActiveRecord::Base def self.separator ',' end def self.tag_string(tags) Array(tags).select { |t| self === t }.map(&:name) * "#{separator} ".squeeze(' ') end module AsString def to_s Tag.tag_string(self) end end end class Post < ActiveRecord::Base has_and_belong_to_many :tags, :extend => Tag::AsString end
This paste will be private.
From the Design Piracy series on my blog: