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
| module CalorieCalculator | |
| def calculate_calories(ingredients) | |
| total_calories = 0 | |
| ingredients.each do |ingredient| | |
| if ingredient.respond_to?(:calorie_count) | |
| total_calories += ingredient.calorie_count | |
| else | |
| raise TypeError, "The ingredient must have a calorie_count" | |
| end | |
| 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
| # IRBRC file originally by Iain Hecker, http://iain.nl | |
| # put all this in your ~/.irbrc | |
| require 'rubygems' if RUBY_VERSION[2] == ?8 # rubygems is only needed in 1.8 | |
| require 'yaml' | |
| require 'irb/completion' | |
| require 'irb/ext/save-history' | |
| IRB.conf[:SAVE_HISTORY] = 1000 | |
| IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb_history" |
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 QuestionsController do | |
| describe "GET 'index'" do | |
| it "returns http success" do | |
| get 'index' | |
| response.should be_success | |
| end | |
| 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
| require 'spec_helper' | |
| describe "Questions" do | |
| describe "GET /questions" do | |
| it "Should respond with success to /quetsions" do | |
| get questions_path | |
| response.status.should be(200) | |
| end | |
| 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
| 1- Decide which one is the “parent” and which one is the “child”. So the parent has_many children | |
| 2- If you are using SQL database add a column to the child ActiveRecord model named parent_id | |
| 3- In the parent ActiveRecord model add has_many :children (notice we used plural in here) | |
| 4- In the child ActiveRecord model add belongs_to :parent (notice we used singular in here) | |
| 5- (optional) Change the child controller to be nested from the parent’s controller in order to re-use methods (mostly for before_filter) by: | |
| a- Makes the routes for the child controller nested inside the “show” action of parent controller | |
| b- Make the child controller inherit from the parent controller. | |
| c- Setup filters as needed | |
| d- Change URLs relating to child controller around your app. |
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
| # ruby 1.8.7 compatible | |
| require 'rubygems' | |
| require 'irb/completion' | |
| # interactive editor: use vim from within irb | |
| begin | |
| require 'interactive_editor' | |
| rescue LoadError => err | |
| warn "Couldn't load interactive_editor: #{err}" | |
| 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
| class TriangleClimber | |
| def initialize(size = nil, grid = nil) | |
| @possible_ways = 0 | |
| @grid = grid ? grid.inject([]) {|r,e| r << e.strip.split(" ")}.reverse : nil | |
| @size = size || @grid.size | |
| end | |
| def find_possible_climbing_ways | |
| 0.upto(@size - 1) {|x| move([0, x]) unless grid_has_trap?([0, x])} |
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
| # ruby 1.8.7 compatible | |
| require 'rubygems' | |
| require 'irb/completion' | |
| # interactive editor: use vim from within irb | |
| begin | |
| require 'interactive_editor' | |
| rescue LoadError => err | |
| warn "Couldn't load interactive_editor: #{err}" | |
| 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
| 2335 Canton Hwy #6 Windsor ON N8N 3N2 | |
| 6 Arch St #9757 Alcida NB E8J 2C4 | |
| 9547 Belmont Rd #21 Belleville ON K8P 1B3 | |
| 73 Pittsford Victor Rd Vancouver BC V5Z 3K2 | |
| 447 Commercial St Se LIle-Perrot QC J7V 4T4 | |
| 47 Garfield Ave Swift Current SK S9H 4V2 | |
| 3 Mill Rd Baker Brook NB E7A 1T3 | |
| 136 W Grand Ave #3 Delhi ON N4B 1C4 | |
| 80 Maplewood Dr #34 Bradford ON L3Z 2S4 | |
| 58 Hancock St Aurora ON L4G 2J7 |
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
| for number in 1..100 | |
| if number % 3 == 0 && number % 5 == 0 | |
| puts "FIZZBUZZ" | |
| elsif number % 3 == 0 | |
| puts "FIZZ" | |
| elsif number % 5 == 0 | |
| puts "BUZZ" | |
| else | |
| puts number | |
| end |
OlderNewer