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
| def assert_equal(expected, actual) | |
| if expected == actual | |
| puts "Joy" | |
| else | |
| puts "Expected #{expected}, got #{actual}" | |
| end | |
| end | |
| each_return = [1,2,3,4].each{|num| num * 5 } | |
| assert_equal [1,2,3,4], each_return |
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
| desc "Create a bunch of seed data for artists and songs" | |
| task :seed_artists_and_songs => [:environment, :clear_artists_and_songs] do | |
| # Build Song Off Artist | |
| # Given a Song called R.E.S.P.E.C.T | |
| # build the Aretha Franklin Artist | |
| s = Song.create(:name => "R.E.S.P.E.C.T") | |
| s.build_artist(:name => "Aretha Franklin") | |
| s.save |
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
| desc "Show the date/time format strings defined and example output" | |
| task :date_formats => :environment do | |
| now = Time.now | |
| [:to_date, :to_datetime, :to_time].each do |conv_meth| | |
| obj = now.send(conv_meth) | |
| puts obj.class.name | |
| puts "=" * obj.class.name.length | |
| name_and_fmts = obj.class::DATE_FORMATS.map { |k, v| [k, %Q('#{String === v ? v : '&proc'}')] } | |
| max_name_size = name_and_fmts.map { |k, _| k.to_s.length }.max + 2 | |
| max_fmt_size = name_and_fmts.map { |_, v| v.length }.max + 1 |
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
| require 'spec_helper' | |
| describe AnswerObserver do | |
| # let(:user) {stub_model(User)} | |
| # let(:answer) {Factory(:answer, :user => user)} | |
| describe '#after_create' do | |
| it "calls update_answer_summary on the answer's user" do | |
| # This tests the implied implentation that the observer's | |
| # after_create will fire on a real answer |
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
| # Assign the Artist to the Song | |
| artist = Artist.create() | |
| song = Song.create() | |
| song.artist = artist | |
| song.save | |
| artist.reload | |
| artist.songs | |
| # Build the Song from the Artist | |
| artist = Artist.create() |
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
| require 'spec_helper' | |
| describe ProfilesController do | |
| context "as a User" do | |
| before(:each) do | |
| @user = Factory(:user) | |
| login_as(@user) | |
| end | |
| context "create a Profile" do |
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
| use Rack::Static, :urls => ["/stylesheets", "/images"], :root => "public" | |
| run lambda { |env| [200, { 'Content-Type' => 'text/html', 'Cache-Control' => 'public, max-age=86400' }, File.open('public/index.html', File::RDONLY)] } |
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
| #ruby19 added ObjectSpace.count_objects method which returns a hash of types+counts of objects in current process #standup | |
| #ruby19 allows default parameters in procs & lambdas! ex: f = -> a,b=1,*c { p [a,b,c] }; f.call(1); f.(1,2); f[1,2,3] #standup | |
| #ruby19 no longer supports .each on a string! instead, use: .chars, .bytes, .lines #standup | |
| #ruby19 supports 3 ways to call a proc! ex: f =->n {[:hello, n]}; f[:ruby]; f.call(:ruby); f.(:ruby) #standup | |
| #ruby19 hashes preserve the insertion order of elements! for the curious: http://bit.ly/e0oEun #standup |
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
| function parse_git_branch { | |
| git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
| } | |
| function superprompt { | |
| local RED="\[\033[0;31m\]" | |
| local LIGHT_RED="\[\033[1;31m\]" | |
| export PS1="\[\e]2;\u@\h\a[\[\e[37;44;1m\]\t\[\e[0m\]]$RED\$(parse_git_branch) \[\e[32m\]\W\[\e[0m\] \$ " | |
| PS2='> ' |
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
| require 'rubygems' | |
| require 'yaml' | |
| require 'irb/completion' | |
| alias q exit | |
| class Object | |
| def local_methods | |
| (methods - Object.instance_methods).sort | |
| end |