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
| i = 1 | |
| until i == 11 | |
| puts i | |
| i += 1 | |
| 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
| puts "This product is available" unless @private |
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
| authors = ["Arthur Conan Doyle", "J.K. Rowling", "J.R.R. Tolkien", "Hanif Kureishi"] | |
| authors.each do |author| | |
| puts author | |
| 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
| # Addition + | |
| 1 + 2 # result 3 | |
| # Subtraction - | |
| 2 - 1 # result 1 | |
| # Multiplication * | |
| 2 * 3 # result 6 | |
| # Division / | |
| 6 / 2 # result 3 | |
| # Modulus % returns the remainder of the left operand divided by the right operand | |
| 7 % 2 # result 1 |
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
| a = 2 | |
| b = 3 | |
| # Equality == | |
| a == b # result false | |
| # Not equal != | |
| a != b # result true | |
| # Greater than > | |
| a > b # result false | |
| # Less than < |
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
| # equals = | |
| a = 2 | |
| # += | |
| a += 1 # a is now 3 | |
| # -= | |
| a -= 1 # a is now 2 again | |
| # Ruby does not have ++ or -- | |
| # *= | |
| a *= 2 # a is now 4 | |
| # /= |
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
| # && the AND operator | |
| true && true # result true | |
| true && false # result false | |
| false && false # result false | |
| # || the OR operator | |
| true || true # result true | |
| true || false # result true | |
| false || false # result false | |
| # ! the NOT operator | |
| !true # result false |
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_stock = true | |
| book_availability = @in_stock ? "In Stock" : "Awaiting Delivery" | |
| puts book_availability # result "In Stock" |
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
| authors = ["Arthur Conan Doyle", "J.K. Rowling", "J.R.R. Tolkien", "Hanif Kureishi"] |
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
| authors = ["Arthur Conan Doyle", "J.K. Rowling", "J.R.R. Tolkien", "Hanif Kureishi"] | |
| authors[0] # => "Arthur Conan Doyle" | |
| authors[1] # => "J.K. Rowling" | |
| authors[2] # => "J.R.R. Tolkien" | |
| authors[3] # => "Hanif Kureishi" |