Sometimes relationships need to be flexible, and that's where we look to polymorphism. Say we want to implement:
- A
Person - A
Company - A
PhoneNumberthat can connect to aPersonor aCompany
| ### | |
| # This is a demonstration of using SQLite3's Virtual File System API in Ruby. | |
| # | |
| # == Synopsis | |
| # | |
| # This program will store its SQLite database after the __END__ line. | |
| # | |
| # === In Detail | |
| # | |
| # SQLite3 uses the DATABase class as a proxy for our IO object. Upon |
| =Navigating= | |
| visit('/projects') | |
| visit(post_comments_path(post)) | |
| =Clicking links and buttons= | |
| click_link('id-of-link') | |
| click_link('Link Text') | |
| click_button('Save') | |
| click('Link Text') # Click either a link or a button | |
| click('Button Value') |
| class Dog | |
| module InstanceMethods | |
| def bark | |
| "Arf arf!" | |
| end | |
| end | |
| include InstanceMethods | |
| end | |
| dog = Dog.new |
| module API | |
| class Version1 < Grape::API | |
| version 'v1' | |
| resource :hotels do | |
| get '/' do | |
| if [:latlng, :query].all? {|key| params[key].blank? } | |
| error! 'Please pass in latlng|query' | |
| end |
| #!/usr/bin/env ruby | |
| # Print the complexity over time for a Ruby method in a | |
| # git repository. | |
| # | |
| # Requires: >= bash ?.? | |
| # >= git 1.7.1 | |
| # >= ruby 1.9.2 | |
| # >= flog 2.5.0 | |
| # |
| require 'net/http' | |
| require 'json' | |
| ### | |
| # Stupid simple class for uploading to imgur. | |
| # | |
| # client = Imgur2.new 'my imgur key' | |
| # p File.open(ARGV[0], 'rb') { |f| | |
| # client.upload f | |
| # } |
| # ~/.tmux.conf | |
| # | |
| # See the following files: | |
| # | |
| # /opt/local/share/doc/tmux/t-williams.conf | |
| # /opt/local/share/doc/tmux/screen-keys.conf | |
| # /opt/local/share/doc/tmux/vim-keys.conf | |
| # | |
| # URLs to read: | |
| # |
| require 'sass' | |
| module Sass::Script::Functions | |
| def svg_circle(radius, color, circle_type) | |
| img = if circle_type.value == "disc" | |
| %Q{<circle cx="#{radius.value}" cy="#{radius.value}" r="#{radius.value}" | |
| stroke-width="0" fill="#{color}"/>} | |
| else | |
| %Q{<circle cx="#{radius.value}" cy="#{radius.value}" r="#{radius.value}" | |
| stroke="#{color}" stroke-width="1" fill="white"/>} |
| # add this to your spec helper | |
| RSpec.configure do |config| | |
| config.treat_symbols_as_metadata_keys_with_true_values = true | |
| config.filter_run :focus => true | |
| config.run_all_when_everything_filtered = true | |
| end | |
| # and then use the :focus tag in your specs | |
| it "does something awesome", :focus do |