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
| describe 'routing another way' do | |
| it { should have_resources(:days) } | |
| it { should get('/days' => 'days#index') } | |
| it { should match('/days' => 'days#index', :via => :get) } | |
| it { should recognize('/days', :via => :get).as('days#index') } | |
| it { should generate('days#index').from('/days', :via => :get) } | |
| it { should recognize('/students/1/days', :via => :get).as('days#index', :student_id => '1') } | |
| end |
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
| # Extend String to include an encryption method | |
| # | |
| # For this to work, you must place this in the lib directory of your Rails project. | |
| # You will also need three files in your config directory: | |
| # * public.pem: Your public key file | |
| # * private.pem: Your private key file | |
| # * passphrase.txt: Your passphrase | |
| class String | |
| require 'openssl' | |
| require 'base64' |
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 'ostruct' | |
| players = Array.new | |
| def new_player(roster, options) | |
| player = OpenStruct.new | |
| player.name = options[:name] | |
| player.sex = options[:sex] | |
| roster.push(player) |
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
| class CutItUp | |
| def singleton_class | |
| class <<self; self; end | |
| end | |
| def lol | |
| puts "LOL" | |
| end | |
| def delete_method(method) |
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
| class Foo | |
| def my_attr_accessor(*args) | |
| args.each do |arg| | |
| # def the_arg | |
| # @the_arg | |
| # end | |
| self.instance_eval("def #{arg}; @#{arg}; end") | |
| # def the_arg=(the_arg) | |
| # @the_arg = the_arg |
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 'rest-client' | |
| require 'json' | |
| twit = Object.new | |
| def twit.get_user_timeline(user_id) | |
| @user_timeline = JSON.parse(RestClient.get("http://api.twitter.com/1/statuses/user_timeline.json?user_id=#{user_id}")) | |
| self.instance_eval do | |
| def statuses |
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
| # Extract Method (http://refactoring.com/catalog/extractMethod.html) | |
| # | |
| # not refactored | |
| # | |
| def self.display_name(login) | |
| ad_entry = self.find(login) | |
| first_name_match = /FirstName:\s*(.*)$/.match(self.find(login)) | |
| last_name_match = /LastName:\s*(.*)$/.match(self.find(login)) | |
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
| /* | |
| * user.watch v1.0: Cross-browser user.watch | |
| * From http://code.eligrey.com/object.watch/ | |
| * | |
| * By Elijah Grey, http://eligrey.com | |
| * Tweaked by Trevor Lalish-Menagh, http://trevmex.com | |
| * | |
| * A shim that partially implements object.watch and object.unwatch | |
| * in browsers that have accessor support. | |
| * |
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
| myNS.caller = function () { | |
| myNS.funct1(); | |
| myNS.funct2(); | |
| myNS.funct3(); | |
| }; |
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
| describe("myNS.log", function () { | |
| it("sends a string to the console log", function () { | |
| spyOn(window.console, "log"); | |
| expect(myNS.log("test message")).toEqual("test message"); | |
| expect(window.console.log).toHaveBeenCalledWith("test message"); | |
| }); | |
| }); |