Install the Rails gem if you haven't done so before
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
| library=# SELECT * FROM books; | |
| id | title | author | |
| ------+------------------------------------------+--------------------- | |
| 1259 | Eloquent Ruby | Russell A. Olson | |
| 1593 | JavaScript: The Good Parts | Douglas Crockford | |
| 8982 | Designing Object-Oriented Software | Rebecca Wirfs-Brock | |
| 7265 | Practical Object-Oriented Design in Ruby | Sandi Metz | |
| (4 rows) |
putsconverts value to string.pdoes no conversion. Prints the true value.- Everything in Ruby is an object!
- The pound sign/hash is for single line comments.
- Multiline comments require
=beginand=end - Integers are whole numbers
- An expression is a bit of code that yeilds a value.
- Math can be performed on string objects.
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
| source 'https://rubygems.org' | |
| git_source(:github) do |repo_name| | |
| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") | |
| "https://github.com/#{repo_name}.git" | |
| end | |
| # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' | |
| gem 'rails', '~> 5.1.2' |
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
| [18] pry(#<Post>):1> | |
| [19] pry(#<Post>):1> nesting | |
| Nesting status: | |
| -- | |
| 0. main (Pry top level) | |
| 1. #<Post> | |
| [20] pry(#<Post>):1> self.to_s | |
| => "#<Post:0x007fd802f21f70>" | |
| [21] pry(#<Post>):1> self.title = 'some new title' | |
| => "some new title" |
The following is an explanation of Ruby blocks and yield by another Bloc mentor (Adam Louis) who was trying to explain it to one of his students.
On my very first day programming, if someone asked me for "the sum of the numbers from 1 to 10", I'd have written:
puts 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
Easy enough.
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
| Test |
- This file declares a class,
Player, instantiates it, and assigns it to a globalplayervariable. - The
Playerclass contains four methods:constructor()playPause()skipTo()setVolume()
- The
constructor()method sets initial values for thecurrentlyPlaying,playState,volume, andsoundObjectproperties.currentlyPlayingis set to the first item inalbum.songs.- The initial
playStateis"stopped".
- The
volumeis set to the number80.
