Chapter 4 Flashcards
true %>
includes application.css for all media types(computer screens and printers ect). to rails developer, this line looks simple.
define full_title helper method. returns base title if no page title is defined
def full_title(page_title = ' ') base_title = "Ruby on Rails Tutorial Sample App if page_title.empty? base_title else page_title + " | " + base_title end end end
you created full_title helper method. change the line in application.html.erb to use this
title>
interpolation
embed expressions into strings (even logic). process of inserting the result of an expression into a string literal (evaluate expression and insert)
comments in rails
lskdjfkd
puts
most commonely used ruby function to print a string. returns nil for nothing
’#{foo} bar’ output
”#{foo} bar”. ruby wont interpolate single quotes
usefulness of single quote literals
show exactly the characters you type
“foobar”.length
6
“foobar”.empty?
false
create if else statements: if s is nil, else if s is empty, else if s include “foo”
if s.nil? "nil" elsif s.empty? "empty" elsif s.include?("foo") "includes foo" end
x = “foo”
y = “”
print out both if both are empty. print one if one of them is empty
print none if x is not empty
puts “both” if x.empty? && y.empty?
puts “one” if x.empty || y.empty?
puts
“x not empty” if !x.empty?
nil.to_s
””
nil.empty?
undefined method nil for nil:NilClass
“foo”.nil?
false
”“.nil?
false
nil.nil?
true
create similar statement to puts “x” if !x.empty? with “unless”
puts “x” unless x.empty?
def string_message(str = ‘ ‘). explain str
default argument str. you can call this method by saying “string_message” without arguments
“foo bar bax”.split
[“foo”, “bar”, “bax”]
“fooxbarxbazx”.split(‘x’)
[“foo”, “bar”, “baz]
a = [42, 8, 17]
a[-1]
17
name the methods you know you can do with:
x = “hello”
.length .empty? .nil? .include?("foo") .split .split("l")