Highlights from Previous Versions Of The Site
Some Content from a previous version of the site
This entry reflects an older version of a library or code samples that may have expired since the time of it’s writing. Investigate the library or code samples further before use.
Has_many :through for Datamapper
1 # has_many :categories, :through => :categorizations 2 3 has_many :categorizations 4 5 has_and_belongs_to_many :categories, 6 :join_table => "categorizations", 7 :left_foreign_key => "post_id", 8 :right_foreign_key => "category_id", 9 :class => "Category"
Installing Merb and Datamapper
1 sudo gem install merb 2 sudo gem install data_objects 3 sudo gem install do_sqlite3 4 sudo gem install do_mysql 5 sudo gem install datamapper 6 sudo gem install merb_datamapper 7 8 # if you see a dyld: NSLinkModule() error 9 10 sudo mkdir /usr/local/mysql/lib/mysql 11 cd /usr/local/mysql/lib/mysql 12 sudo ln -s /usr/local/mysql/lib/*.dylib .
Handy Ruby Shortcuts
1 # Strings 2 String.new(str="") 3 "new string here" 4 %{new string} 5 %Q{ new string with ' and " escaped } 6 "I want #{variable} expressed" # expressing a variable in a string 7 8 # Arrays 9 Array.new 10 Array.new(size=0, obj=nil) # array of size length filled with objs 11 Array.new(size) {|index| block } # array of size length filled with result of block 12 [foo, bar, bitty] 13 %w{foo bar bitty} 14 15 # Hashes 16 Hash.new 17 Hash.new(obj) # hash whose new values default to obj 18 Hash.new {|hash, key| block } # hash whose new values default to result of block 19 { "foo" => "bar", "bitty" => 0} 20 21 # Regex 22 Regexp.new(string [, options [, lang]]) # supply a string 23 Regexp.new(regexp) # introspective 24 Regexp.compile(string [, options [, lang]]) # supply a string 25 Regexp.compile(regexp) # supply a regex 26 /regex/ 27 %r{regex} # => regex with escaped /