Skip to content

Instantly share code, notes, and snippets.

@nordringrayhide
Created October 13, 2010 13:54
Show Gist options
  • Save nordringrayhide/624065 to your computer and use it in GitHub Desktop.
Save nordringrayhide/624065 to your computer and use it in GitHub Desktop.
==begin
def self.options_for_select(story)
options = []
options << ["",""] if story.story_type_id.nil?
all.map{|story_type| options<<[story_type.title,story_type.id]}
options
end
==end
irb(main):021:0> [1,2,5].inject( true ? [nil] : [] ){|a, b| a + [b, 1]}
=> [nil, 1, 1, 2, 1, 5, 1]
irb(main):022:0> [1,2,5].inject( false ? [nil] : [] ){|a, b| a + [b, 1]}
=> [1, 1, 2, 1, 5, 1]
Conclusion
def self.options_for_select(story)
self.all.inject(story.story_type.present? ? [] : [nil]) {|options, item| options + [item.title, item.id]}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment