"✌️"are both arguments to the method
Arraycan be any Ruby object — even another
Arraycan be created like any Ruby object, by calling
.newon the class:
.push()method, which takes one argument; the object you want to add to the end of the array:
1as you might expect.
.gsub(), require additional data to do their job:
.gsub()needs to know which substring to replace and what to replace it with.
.each, require additional instructions to do their job:
.eachmethod needs to know what code to execute once per element in the array that it was invoked upon.
dokeyword after its name, and then put a matching
endkeyword on a line somewhere after that. Between the
end, we can write as many lines of code as necessary, and those lines of code will be passed to the method as input.
end, you can just use
}. So you might come across some Ruby that looks like this:
=) both to put things in our boxes initially and to replace them later (never to be confused with the similar looking but completely different equivalence comparison (
nil, it can be hard to debug.
Fixnums). Decimals are a class (in Ruby they are called
Symbol, and many more are all classes in Ruby.
classkeyword, we can define our own classes in Ruby and add them to the language, which gives us tremendous expressiveness to describe our problem domain.
Array-like things; populate itself, sort itself:
defis followed by the name of the method you want to define, and comes within the
classthat you are adding a behavior to.
end, so just type the
endbefore you type anything else and forget it.
<h3>, not an
<h6>— regardless of what font size you want it to have. Styling is secondary, and we will always override 100% of the crappy default browser styling anyway. What is not secondary is search engine rankings and accessibility, for which choosing the correct semantic elements is very important.
<recipe></recipe>is not an element in the HTML language. So, instead, HTML offers us
<div>is the generic block-level element that we use when no other element makes sense. And then we usually add a
class="recipe"to it to distinguish it from all the other
<span>is the analogous generic inline element.)
bundleof lots of other gems).
Hashconsists of a key/value pair. The key comes first and is separated from the value by a
=>, which is called a hash rocket.
Symbols, if we have a choice in the matter.
Hashcan be created like any Ruby object, by calling
.newon the class:
.store()method, which takes two arguments; the first is the key you want to store an object under, and the second is the object you want to store:
@as the first letter in its name, rather than a lowercase letter like we're used to for local variables.
<label>is an HTML element that is paired with an
<form>. It is best practice to always pair every
<label>, even if you hide it with CSS, for accessibility and SEO reasons.
<input>pair should have matching
id=""attributes, like so:
6 * 7so that we wouldn't all go crazy typing
6.*(7)all the time.
<<), exponentiation (
=FOR THE EQUIVALENCE COMPARISON
if, CHECK YOURSELF and DO NOT TYPE A SINGLE
=IN THE LOGICAL TEST AFTER IT.
render()method is what we use at the end of a controller action to choose which
.html.erbview template to send back to the user.