This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This module should be used for situations where enumerating over constant values is desired. | |
# This facilitates keeping the code DRY by keeping the constant values defined in one place, and | |
# still having the ability to enumerate over them wherever they are needed. | |
# | |
# Example use cases: | |
# | |
# * defining constants for possible field values in an AR object and including this module to | |
# provide access to the values in a 'validates_inclusion_of' validation | |
# * defining constants for select box values in a view and including this module to allow them to be | |
# enumerated over in the select tag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pick up to 10 names, making sure to draw from each "hat" at least once | |
class Name < Struct.new(:first, :last); end | |
max_names = 10 | |
hat1 = [Name.new('Abraham', 'Lincoln'), Name.new('George', 'Washington')] | |
hat2 = [Name.new('Thomas', 'Jefferson'), Name.new('James', 'Madison'), Name.new('Theodore', 'Roosevelt'), Name.new('John', 'Kennedy')] | |
hat3 = [Name.new('Calvin', 'Coolidge'), Name.new('Ronald', 'Regan'), Name.new('Woodrow', 'Wilson')] | |
[hat1, hat2, hat3].sort{|a,b| b.size <=> a.size}.inject{|memo, names| memo.zip(names)}.flatten.compact[0, max_names] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# open the file containing the gems to load and install each | |
File.open(Dir.pwd << "/gems.txt", "r") do |f| | |
while (line = f.gets) | |
puts `sudo gem install --no-ri --no-rdoc #{line}` unless line.strip.empty? | |
end | |
end |
NewerOlder