Академический Документы
Профессиональный Документы
Культура Документы
local variable local_variable ERB Embedded Ruby for making if/else if input == admin_password
Comparison ==, !=, >, >=, <, <= answer = (num + Save result of Research
Operators other_num) * 6 adding/multiplying.
Cmd+Click (Mac) or Open links in new
Return Last line of a ruby Ctrl+Click tabs.
Value method/block/expression in IRB String Interpolation
ruby-doc.org ("The Ruby coding best
Boolean true or false dog_speak = puts "Dogs say # Ruby Docs") practices.
nil counts as false in Ruby, "woof!" {dog_speak}" Stack Overflow Oops. Research your
everything counts as true error.
or puts "Dogs say " +
Array (0 letters = ["a", "b", dog_speak Guides and blog posts Has someone done
indexed) "c"] this before?
cheatography.com/laurennicoleroth/
RubyForBeginners Cheat Sheet
by laurennicoleroth via cheatography.com/26292/cs/7316/
Sinatra Framework for building a web push Add to end of array: letters << Remove person.delete(:sex) #
server written in Ruby "elephant" or value by returns "female"
key.
Routing Action taken in response to letters.push("elephant")
request
<< Shovel operator. Push to end of
Methods
Path text and slashes after domain array.
http://localh Sinatra looks for get '/hello' Greeting Method def
unshift Add element to beginning of array:
ost:4567/he Accepts Name create_greeting(nam
letters.unshift("zebra")
llo e)
pop Remove from end of array.
get '/hello' do return "Welcome, #
letters.pop
#code to return a {name}"
shift Remove from start of array.
response to the browser letters.shift end
end .method Call a method with arguments. Call Greeting create_greeting("La
String get '/hello' (argum Some methods require no Method uren")
Response ents) arguments.
#returns 'Welcome,
"Hello, friendly web letters Method without arguments. Lauren"
traveler!" .pop
Upcase On Call create_greeting("La
end To Greeting uren").upcase
Hashes Method
HTML File get '/hello' do
Response Instantiate person = {:name => Arguments Input given to methods.
erb :hello a Hash "Lauren", :age => 89, Parameters Define what can be
(hash :sex => "female"} passed to a method.
end
rockets)
Return value Output from a function
Get tweets get '/' do Instantiate person = {name:
Implicit Return Returning last line of
route a Hash "Lauren", age: 89, sex: method without explicit
@tweets = (shortcut) "female"} "return"
$client.user_timeline.map
Access person[:name] # returns
{ |tweet| tweet.text } value by Command Line
"Lauren"
erb :index key.
Ruby Download, install, and use ruby
Update person[:age] = 12 gems software packages on your system
end
value by
$ Get Ruby Version
Redirect Get server to run code in get '/' key.
route ruby
'/'
Insert key, person[:gender] = "cis
-v
value pair. female"
$ Load up interactive Ruby
irb
cheatography.com/laurennicoleroth/
RubyForBeginners Cheat Sheet
by laurennicoleroth via cheatography.com/26292/cs/7316/
$ gem install Install sinatra gem times 10.times do Set up require twitter
sinatra Twitter
puts "Hello!"
$client
$ gem install Install twitter gem
end global
twitter variable
times 10.times do |counter|
$ ruby Tell Ruby interpreter to loop with $client =
server.rb run code. counter Twitter::REST::Client.new
Sign Up apps.twitter.com
To Use
Twitter
API
cheatography.com/laurennicoleroth/