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 FakeArray | |
attr_reader :info | |
def initialize | |
@info = ["puppies", "kittens", "baby sloths", "puppies"] | |
end | |
def each | |
@info.each do |element| | |
yield element if block_given? |
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
(rdb:1) Dog.find_by_id(13) | |
#<Mysql2::Result:0x007fd2329a2c50 @query_options={:as=>:hash, :async=>false, :cast_booleans=>false, :symbolize_keys=>false, :database_timezone=>:local, :application_timezone=>nil, :cache_rows=>true, :connect_flags=>2147525125, :cast=>true, :default_file=>nil, :default_group=>nil, :host=>"localhost", :username=>"root", :database=>"dogs"}> |
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
(rdb:1) Dog.find_by_id(13).first | |
{"id"=>13, "name"=>"sara", "color"=>"red"} |
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 self.find_by_id(id) | |
results = self.db.query (" | |
SELECT * | |
FROM dogs | |
WHERE id = #{id} | |
") | |
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
/* descendant selector */ | |
ul li { | |
color: purple; | |
} | |
/* child combinator selector */ | |
ul > li { | |
text-transform: uppercase; | |
} | |
/* adjacent sibling combinator */ | |
p + p { |
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
# in config/routes.rb | |
RailsSampleApp::Application.routes.draw do | |
resources :posts | |
# SHORTCUT VERB ROUTE CONTROLLER#ACTION | |
# posts GET /posts(.:format) posts#index | |
# POST /posts(.:format) posts#create | |
# new_post GET /posts/new(.:format) posts#new | |
# edit_post GET /posts/:id/edit(.:format) posts#edit | |
# post GET /posts/:id(.:format) posts#show | |
# PUT /posts/:id(.:format) posts#update |
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 App < Sinatra::Application | |
get '/' do | |
@meal = Mealtime.new(Time.now) | |
erb :index | |
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
/* JavaScript example of loose typing */ | |
var a = "twenty two"; // String delcaration | |
var b = 22; // Number declaration | |
/* ActiveRecord example of strong typing */ | |
create_table do |t| | |
t.string name | |
t.integer age | |
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
var a = "sarah"; | |
function dance_with_gus(some_var){ | |
a = "gus"; | |
return(some_var + " dances with " + a ); | |
} | |
// "gus dances with gus" | |
var a = "sarah"; | |
function dance_with_gus(some_var){ | |
var a; |
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
Perform these exercises in the JavaScript console of your favorite web browser. | |
What does the following expression return? | |
> 3 + 2; | |
5 | |
============================================================= | |
What does the following expression return? | |
> typeof(3); |